103

I'm new to Grunt. I'm trying to configure Grunt on my Mac OSX Lion.

I followed the instructions here and then created a project folder that contains the files below. When I try to run by typing "grunt" into terminal I get command not found. I've also modified my paths sudo nano /etc/paths in the hope that adding the path would make the task runner work but it's still not working. Can someone assist with this please?

---paths

/usr/bin 
/bin
/usr/sbin
/sbin
/usr/local/bin
/usr/local/bin/grunt


--- files
node modules
Gruntfile.js
package.json
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130
user686483
  • 1,584
  • 6
  • 18
  • 29

6 Answers6

509

My fix for this on Mountain Lion was: -

npm install -g grunt-cli 

Saw it on http://gruntjs.com/getting-started

Jason Swett
  • 43,526
  • 67
  • 220
  • 351
user2792249
  • 9,123
  • 3
  • 13
  • 3
46

I'm guessing you used Brew to install Node, so the guide here might be helpful http://madebyhoundstooth.com/blog/install-node-with-homebrew-on-os-x/.

You need to ensure that the npm/bin is in your path as it describes export PATH="/usr/local/share/npm/bin:$PATH". This is the location that npm will install the bin stubs for the installed packages.


The nano version will also work as described here http://architectryan.com/2012/10/02/add-to-the-path-on-mac-os-x-mountain-lion/ but a restart of Terminal may be required to have the new path picked up.

nschonni
  • 4,069
  • 1
  • 28
  • 37
13

For windows

npm install -g grunt-cli

npm install load-grunt-tasks

Then run

grunt

simeg
  • 1,889
  • 2
  • 26
  • 34
Mohit Singh
  • 5,977
  • 2
  • 24
  • 25
6

I have been hunting around trying to solve this one for a while and none of the suggested updates to bash seemed to be working. What I discovered was that some point my npm root was modified such that it was pointing to a Users/USER_NAME/.node/node_modules while the actual installation of npm was living at /usr/local/lib/node_modules. You can check this by running npm root and npm root -g (for the global installation). To correct the path you can call npm config set prefix /usr/local.

simeg
  • 1,889
  • 2
  • 26
  • 34
Bueno
  • 1,840
  • 2
  • 15
  • 17
6

Also on OS X (El Capitan), been having this same issue all morning.

I was running the command "npm install -g grunt-cli" command from within a directory where my project was.

I tried again from my home directory (i.e. 'cd ~') and it installed as before, except now I can run the grunt command and it is recognised.

Mongo0se
  • 173
  • 2
  • 11
5

the key point is finding the right path where your grunt was installed. I installed grunt through npm, but my grunt path was /Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin/grunt. So after I added /Users/${whoyouare}/.npm-global/lib/node_modules/grunt/bin to ~/.bash_profile,and source ~/.bash_profile, It worked.

So the steps are as followings:

1. find the path where your grunt was installed(when you installed grunt, it told you. if you don't remember, you can install it one more time)

2. vi ~/.bash_profile

3. export PATH=$PATH:/your/path/where/grunt/was/installed

4. source ~/.bash_profile

You can refer http://www.hongkiat.com/blog/grunt-command-not-found/

YJ. Yang
  • 978
  • 2
  • 11
  • 19
  • Great answer, worked for me (Win7 x64). This is what I placed in my .bash_profile: `export PATH=$PATH:/Users//AppData/Roaming/npm/node_modules/grunt-cli/bin/grunt` – k_rollo Mar 13 '17 at 02:13
  • Also check `~/.npm-packages/lib/node_modules/grunt-cli/bin/grunt` (OS X High Sierra) – kubilay Nov 03 '18 at 17:00