Richard
Richard

Reputation: 65600

grunt: command not found

npm knows that grunt is installed globally, so why isn't it found?

$ npm install -g grunt
... installs ...
$ npm list -g | grep grunt
│   ├─┬ [email protected]
│   ├─┬ [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ ├── [email protected]
$ grunt
-bash: grunt: command not found

I assume because it's put it somewhere that is not on my PATH.

Why doesn't npm just put it somewhere that is on my PATH by default, like /usr/local/bin?

UPDATE: Weirdly, I get the same grunt: command not found error even after I do npm install grunt to run it locally. What am I doing wrong? There is a Gruntfile.js in my repo.

Upvotes: 3

Views: 10341

Answers (2)

Ben Haran
Ben Haran

Reputation: 21

For me there was another thing missing, adding the path to NPM's folder in Window's env variables

  • Go to System (My computer->Properties)
  • Advanced System Settings
  • In Advanced tab, 'Environment Variables'
  • Under User variables, choose Path, then Edit
  • Add this alongside the others you have: '%USERPROFILE%\AppData\Roaming\npm'

Hope this helps, g'luck

Upvotes: 2

Explosion Pills
Explosion Pills

Reputation: 191799

The package "grunt" is the task runner itself whereas the "grunt-cli" package is the command line interface that includes the grunt executable. You can make sure that it is installed to the correct path.

If you do npm install grunt-cli it still would not work because this would be installed to node_modules in the corresponding directory which is most likely not on your path. However, when you use grunt from the globally installed CLI tool it will look for an installation of grunt that is local to that project as well as the Gruntfile.js

what you have to do is

  1. install grunt-cli globally:

    $ npm install grunt-cli -g

  2. install grunt local in your dependencies (optionally save the dependency to your package.json):

    $ npm install grunt --save

Upvotes: 11

Related Questions