[node.js] Node package ( Grunt ) installed but not available

I'm trying to build a github jquery-ui library using grunt, but after running npm install I still can't run the command according to the readme file. It just gives No command 'grunt' found:

james@ubuntu:~/Documents/projects/ad2/lib/jquery-ui$ grunt build
No command 'grunt' found, did you mean:
 Command 'grun' from package 'grun' (universe)
grunt: command not found
james@ubuntu:~/Documents/projects/ad2/lib/jquery-ui$ npm ls
[email protected] /home/james/Documents/projects/ad2/lib/jquery-ui
+-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ ¦   ¦ +-- [email protected] 
¦ ¦   +-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
¦ ¦ +-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
+-- [email protected] 
+-- [email protected] 
¦ +-- [email protected] 
¦ +-- [email protected] 
+-- [email protected] 
+-- [email protected] 
+-- [email protected] 
¦ +-- [email protected] 
+-- [email protected] 
  +-- [email protected] 

I'm confused, what am I missing please?

This question is related to node.js build package npm

The answer is


On Windows, part of the mystery appears to be where npm installs the Grunt.cmd file. While on my Linux box, I just had to run sudo npm install -g grunt-cli, on my Windows 8 work laptop, Grunt was placed in the '.npm-global' directory: %USER_HOME%\.npm-global and I had to add that to the Path.

So on Windows my steps were:

  • npm install -g grunt-cli

  • figure out where the heck grunt.cmd was (I guess for some it is in %USER_HOME%\App_Data\Roaming)

  • Added the location to my Path environment variable. Opened a new cmd prompt and the grunt command ran fine.


If you did have installed Grunt package by running npm install -g grunt and it still say's No command 'grunt' found or grunt: command not found, a quick and dirty way to get this working is linking node binaries to your $PATH manually.

On MacOSX/Linux you can add this line to your ~/.bash_profile or ~/.bashrc file.

PATH=$PATH:/usr/local/Cellar/node/HEAD/bin # Add NPM binaries

You probably should replace /usr/local/Cellar/node/HEAD/bin by the path where your node binaries could be found.

If this is quick and dirty to me, it's because everything should work without doing this, but for an unknown reason, a link seem broken. As nobody on IRC could tell me why this happened, I found my own way to make it (grunt) work.

PS: This should help you make grunt works, this answer is not jquery-ui related.

Update 02/2013 : You should take a look at @tom-p's answer which explains better what is going on. Tom gives us the real solution instead of hacking your bashrc file : both should work, but you should try installing grunt-cli first.


  1. Instala grunt de manera global: sudo npm install -g grunt-cli --unsafe-perm=true --allow-root

  2. Try to run grunt.

  3. If you have this message:

Warning:

You need to have Ruby and Sass installed and in your PATH for this task to work.

More info: https://github.com/gruntjs/grunt-contrib-sass

Used --force, continuing.

3.1. Check that you have ruby installed (mac, you should have it): ruby -v


On Windows 10 Add this to your Path:

%APPDATA%\npm

This references the folder ~/AppData/Roaming/npm

[Assumes that you have already run npm install -g grunt-cli]


Hello I had this problem on mac, and what I did was

installed globally and prefix with global path

sudo npm install grunt -g --prefix=/usr/local

now $ which grunt

should out put /usr/local/bin/grunt

Cheers


Other solution is to remove the ubuntu bundler in my case i used:

sudo apt-get remove ruby-bundler 

That worked for me.


In my case, i need modify the file /usr/local/bin/grunt in line 1 ( don't make this ):

 #!/usr/bin/env node //remove this line
 #!/usr/bin/env nodejs // and put this line to run with nodejs

Edited:

To avoid problems, I created a link with the name of "node" because many other programs still use "node" command.

 sudo ln -s /usr/bin/nodejs /usr/sbin/node

The right way to install grunt is by running this command:

npm install grunt -g

(Prepend "sudo" to the command above if you get a EACCESS error message)

-g will make npm install the package globally, so you will be able to use it whenever you want in your current machine.


On WIN7 I had to manually add the path to the npm folder (which contains the elusive 'grunt' file) to the Windows PATH environmental variable.
In my case that was C:\Users\mhaagsma\AppData\Roaming\npm


Add /usr/local/share/npm/bin/ to your $PATH


There is one more way to run grunt on windows, without adding anything globally. This is a case when you don't have to do anything with %PATH%

if you have grunt and grunt-cli installed (without -g switch). Either by:

npm install grunt-cli
npm install [email protected]

Or by having that in your packages.json file like:

"devDependencies": {
    "grunt-cli": "^1.2.0",
    "grunt": "^0.4.5",

You can call grunt from your local installation by:

node node_modules\grunt-cli\bin\grunt --version

This is a solution for those who for some reasons don't want to or can't play with PATH, or have something else messing it all the time, for instance on a build agent.

Edit: Added versions as the grunt-cli works with grunt > 0.3


Sometimes you have to npm install package_name -g for it to work.


Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to build

error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' WARNING in budgets, maximum exceeded for initial How can I change the app display name build with Flutter? Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0) Still getting warning : Configuration 'compile' is obsolete and has been replaced with 'implementation' Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details Component is part of the declaration of 2 modules Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven

Examples related to package

ModuleNotFoundError: No module named 'sklearn' Python: How to pip install opencv2 with specific version 2.4.9? Relative imports - ModuleNotFoundError: No module named x Is __init__.py not required for packages in Python 3.3+ "pip install unroll": "python setup.py egg_info" failed with error code 1 Unable to Install Any Package in Visual Studio 2015 beyond top level package error in relative import How can I specify the required Node.js version in package.json? "installation of package 'FILE_PATH' had non-zero exit status" in R Error in installation a R package

Examples related to npm

What does 'x packages are looking for funding' mean when running `npm install`? error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean` What exactly is the 'react-scripts start' command? On npm install: Unhandled rejection Error: EACCES: permission denied Difference between npx and npm?