29

I'm trying to use grunt with sass and have been following these guides:

I've:

  • Intsalled node.js

  • Installed the command-line version of grunt: sudo npm install -g grunt -cli

  • Added the path from the grunt installer to my bash profile: export PATH=/usr/local/lib/node_modules/grunt/bin:$PATH

  • Made the profile an executable: source ~/.bash_profile

  • Setup package.json and Gruntfile.js files in my project root

  • Installed grunt into the project: cd /path/to/project/root/ and sudo npm install

But when I try to run grunt I see: command not found

It's the same if I run: grunt --version

I wasn't sure if the bash path needs /bin on the end as per the blog posted above but have tried it both ways: /usr/local/lib/node_modules/grunt/ and /usr/local/lib/node_modules/grunt/bin/

I've also run the grunt installer several times but didn't see any errors so am positive it's installed - can anyone see what I'm doing wrong? I'm running OSX mavericks incase this is the issue.

Any pointers in the right direction would be much appreciated.

Cheers

CMSCSS
  • 2,076
  • 9
  • 28
  • 49
  • 3
    not sure if it's just a typo, but the package is named `grunt-cli` without the space in between. – thomaux Jan 09 '14 at 10:05
  • 1
    @Anzeo - that was it! So the non-cli version was being installed maybe? Cheers – CMSCSS Jan 09 '14 at 10:10
  • Yes, it just installed grunt with a -cli flag (that has no meaning) :) I'll add the comment as an answer so you can accept and close the question. – thomaux Jan 09 '14 at 10:45
  • possible duplicate of [Node package ( Grunt ) installed but not available](http://stackoverflow.com/questions/10667381/node-package-grunt-installed-but-not-available) – AdrieanKhisbe Jan 23 '15 at 08:22

5 Answers5

61

You have a typo in your command. The package is named grunt-cli without the space.

Update the command to:

sudo npm install -g grunt-cli

And all should work as expected.

thomaux
  • 19,133
  • 10
  • 76
  • 103
  • 10
    should not have to use sudo to install npm packages: http://foohack.com/2010/08/intro-to-npm/#what_no_sudo – winkerVSbecks Apr 21 '14 at 03:42
  • 1
    I simply copied over the command of the OP and corrected the mistake, but thanks for the info! – thomaux Apr 21 '14 at 07:18
  • 6
    Actually, 'sudo' is required when installing grunt. If you don't use sudo, it gets installed, but there's no executable! – JESii May 22 '14 at 13:47
  • 1
    Daniel Kmak, where are your sources that it's not required? Check: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md. If you're using nvm or have followed the steps in the link I have provided you do not need `sudo` in all other cases you'll need to install it with sudo to get an executable. Also, please note we're talking about global packages here. – thomaux Sep 18 '18 at 10:02
  • 2
    @DanielKmak while i agree you should not be blindly using sudo, Grunt's website says the following: " In order to get started, you'll want to install Grunt's command line interface (CLI) globally. You may need to use sudo (for OSX, *nix, BSD etc) or run your command shell as Administrator (for Windows) to do this." – Tyler Kemme May 23 '19 at 18:26
3

Hope this solution also might be helpful to someone. In my case it was a bit trickier.

In command line type the following command

 npm install grunt-cli -g

This will show you the location where the grun client is installed: Copy this location and paste it into a file browser. Was this in my case.

 C:\Users\zkhaymed\AppData\Roaming\npm\node_modules\grunt-cli\bin

This will open you the location of a grunt file. Click on the address line of the location and copy it as a text clicking on the right mouse button. Now go to the Advanced properties of the system at control panel, and paste this address into a System variables and user variables without deleting the other variables.

0

I was having a very similar issue, hopefully this helps.

1) You want to check where node and npm are actually installed. If you used a package manager, such as Homebrew or MacPorts, there may be an issue with the location. Just use the downloadable installer from node.js website. Make sure to use the current version, not the long term support (LTS). The installer will install node and npm in /usr/local/bin, which should already be in your PATH. If you already have node/npm installed you can use which node and which npm to see where they are currently located. You should see /usr/local/bin/node and /usr/local/bin/npm, respectively. You will need to update npm after installing with npm update -g npm. This may require sudo.

2) Once node and npm are correctly installed/updated go to the project's root directory (where you have the Gruntfile.js and package.json) and install Grunt using npm install grunt --save-dev. Remember that Grunt After doing so you should see a new folder called node_modules.

3) Make sure to do the previous step before installing the CLI. You can use Grunt's getting started documentation to help guide you the rest of the way. Just be aware that the instructions for installing Grunt are further down the page than installing the CLI, which makes it somewhat confusing. When Grunt and Grunt-CLI are installed run npm install and run grunt in the command line to execute your Gruntfile.js.

You should now be able to see the versions installed. Note that if you are outside of a project's root directory you will not see a version of Grunt but you will see the Grunt-CLI version. This is because the CLI was installed globally (used from any directory/subdirectory) but Grunt is installed on a per-project basis.

Hopefully this helps!

schaefferda
  • 338
  • 1
  • 4
  • 14
0

I just ran into this scenario as well. The following worked for me:

Try deleting C:/Users/{username}/AppData/Roaming/npm and C:/Users/{username}/AppData/Roaming/npm-cache (if it exists) and reinstalling global npm modules.

Source: https://github.com/nodejs/node/issues/29287

Great Scott
  • 1,325
  • 15
  • 22
-1

I had to add this to the PATH (on a Mac after brew install node ):

export NPM_HOME=/usr/local/Cellar/node/6.3.1/libexec/npm

The npm install was not effective, no matter what args I passed to it.

djangofan
  • 28,471
  • 61
  • 196
  • 289