190

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
jquery-ui@1.9.0pre /home/james/Documents/projects/ad2/lib/jquery-ui
├─┬ grunt@0.3.9 
│ ├── async@0.1.18 
│ ├── colors@0.6.0-1 
│ ├─┬ connect@1.8.7 
│ │ ├── formidable@1.0.9 
│ │ ├── mime@1.2.5 
│ │ └── qs@0.5.0 
│ ├── dateformat@1.0.2-1.2.3 
│ ├─┬ glob-whatev@0.1.6 
│ │ └─┬ minimatch@0.2.4 
│ │   └── lru-cache@1.0.6 
│ ├─┬ gzip-js@0.3.1 
│ │ ├── crc32@0.2.2 
│ │ └── deflate-js@0.2.2 
│ ├── hooker@0.2.3 
│ ├─┬ jshint@0.5.9 
│ │ ├── argsparser@0.0.6 
│ │ └─┬ minimatch@0.2.4 
│ │   └── lru-cache@1.0.6 
│ ├─┬ nodeunit@0.6.4 
│ │ ├── tap-assert@0.0.10 
│ │ └─┬ tap-producer@0.0.1 
│ │   ├── inherits@1.0.0 
│ │   ├── tap-results@0.0.2 
│ │   └── yamlish@0.0.5 
│ ├─┬ nopt@1.0.10 
│ │ └── abbrev@1.0.3 
│ ├─┬ prompt@0.1.12 
│ │ ├── pkginfo@0.2.3 
│ │ └─┬ winston@0.5.11 
│ │   ├── eyes@0.1.7 
│ │   ├─┬ loggly@0.3.11 
│ │   │ └── timespan@2.2.0 
│ │   └── stack-trace@0.0.6 
│ ├── semver@1.0.13 
│ ├─┬ temporary@0.0.2 
│ │ └── package@1.0.0 
│ ├── uglify-js@1.0.7 
│ ├── underscore@1.2.4 
│ └── underscore.string@2.1.1 
├── grunt-compare-size@0.1.4 
├─┬ grunt-css@0.2.0 
│ ├── csslint@0.9.8 
│ └── sqwish@0.2.0 
├── grunt-html@0.1.1 
├── request@2.9.153 
├─┬ rimraf@2.0.1 
│ └── graceful-fs@1.1.8 
└─┬ testswarm@0.2.2 
  └── request@2.9.202 

I'm confused, what am I missing please?

Air
  • 5,084
  • 5
  • 25
  • 19
AJP
  • 26,547
  • 23
  • 88
  • 127

14 Answers14

417

The command line tools are not included with the latest version of Grunt (0.4 at time of writing) instead you need to install them separately.

This is a good idea because it means you can have different versions of Grunt running on different projects but still use the nice concise grunt command to run them.

So first install the grunt cli tools globally:

npm install -g grunt-cli

(or possibly sudo npm install -g grunt-cli ).

You can establish that's working by typing grunt --version

Now you can install the current version of Grunt local to your project. So from your project's location...

npm install grunt --save-dev

The save-dev switch isn't strictly necessary but is a good idea because it will mark grunt in its package.json devDependencies section as a development only module.

Tom P
  • 5,539
  • 1
  • 21
  • 24
  • 5
    I couldn't find grunt folder path in the Path System Variables after running npm install -g grunt-cli – blogbydev Apr 02 '14 at 06:39
  • 10
    had to run using sudo – Phil Hudson Nov 17 '14 at 18:59
  • 2
    If this doesn't work for you, try uninstall grunt and grunt-cli and then doing it again. Only works for me if I use `sudo` Thank you Tom! – Termato Feb 03 '16 at 20:00
  • Note: If you have to use sudo that's to do with how you have node setup. It's not ideal but can be fixed. [sindresorhus suggests one way](https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md). I prefer to use [NVM](https://github.com/creationix/nvm) (node version manager) – Tom P Mar 21 '17 at 13:47
  • 1
    If you're here and you hit `node not found` after running the above command and you used the package manager to install node then you also need to symlink `sudo ln -s /usr/local/bin/nodejs /usr/local/bin/node` – fIwJlxSzApHEZIl May 04 '17 at 01:47
26

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

Sam Figueroa
  • 2,301
  • 22
  • 21
24

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.

Community
  • 1
  • 1
rayfranco
  • 3,630
  • 3
  • 26
  • 38
12

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
Edgard Leal
  • 2,592
  • 26
  • 30
  • 6
    Constructive downvote to dissuade anyone from manually editing packaged files. For your problem you need to `apt-get install nodejs-legacy`. – Air May 30 '14 at 13:02
  • Your suggestion is one of the newest and only suggestion that worked on my brand new install of Debian Jessie. – Post Impatica May 19 '15 at 03:41
  • Ok Air, but i am using OSX, i will try some thing like `brew install nodejs-leacy` – Edgard Leal May 19 '15 at 13:30
  • @Air thanks that was my problem. After following all the previous steps, it was unable to recognize **grunt**. – kemicofa ghost Sep 20 '15 at 21:38
12

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 grunt@0.4.5

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

tomajar
  • 419
  • 5
  • 7
11

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

Ganesh Jadhav
  • 2,830
  • 1
  • 20
  • 32
Marvin
  • 389
  • 4
  • 10
4

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

Theva
  • 873
  • 8
  • 15
2

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.

Adonis K. Kakoulidis
  • 4,951
  • 6
  • 34
  • 43
1
  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

chicacode
  • 41
  • 5
0

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

lowerkey
  • 8,105
  • 17
  • 68
  • 102
  • Thanks for the answer. I've found a different way round what I was trying to do. – AJP May 19 '12 at 18:50
  • @AJP could you tell us how you make it works, instead of just telling us you did ? Thanks. – rayfranco Aug 15 '12 at 12:44
  • @rayfranco sorry I basically got round it by giving up... I think we were trying to make the jquery-ui library perhaps, so we just downloaded it, can't really remember now though... Sorry I know that's not useful, please post back the solution when you find it. It looks like many others have come to this page (without any success). – AJP Aug 15 '12 at 16:15
0

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

sudo apt-get remove ruby-bundler 

That worked for me.

Israel Morales
  • 1,681
  • 1
  • 14
  • 6
0

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.

MattC
  • 5,874
  • 1
  • 47
  • 40
0

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]

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
jomofrodo
  • 1,119
  • 11
  • 19
0

I installed grunt as a development dependency. For some reason I had the NODE_ENV set to production (eg. export NODE_ENV=production) so when I run npm i what got installed were the production dependencies instead the development dependencies.

To get it fixed all I had to do was to fix the respective environment variable, so by export NODE_ENV=development followed by npm i the development dependencies installed as they should in the first place.

Probably this is a rare case but if nothing else works then it is worth checking these premises too.

Eugen Mihailescu
  • 3,553
  • 2
  • 32
  • 29