403

I removed the old version of grunt first, then I installed the new grunt version, and then I got this error:

D:\www\grunt-test\grunt grunt-cli: The grunt command line interface. (v0.1.4)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide: http://gruntjs.com/getting-started

Is this because there is not a reference to grunt in my system path? Or something else? I tried to re-install it a few times already.

vancy-pants
  • 1,070
  • 12
  • 13
Ryan Yiada
  • 4,739
  • 4
  • 18
  • 20
  • 6
    Did you install globally? `npm install grunt -g` – elclanrs Dec 18 '12 at 03:43
  • 1
    do you have a `Gruntfile.js` at the root of your project? – Simon Boudrias Dec 18 '12 at 03:44
  • @elclanrs Yes,I do this. – Ryan Yiada Dec 18 '12 at 03:45
  • @Simon Boudrias Gruntfile.js is in the grunt-test directory. – Ryan Yiada Dec 18 '12 at 03:47
  • This question is closed, but in case it helps anyone else: in my case I had simply forgotten to add `grunt` itself to my `package.json`. The new version of `grunt-cli` doesn't actually install grunt, it relies on the package being there. – Romain May 16 '13 at 23:59
  • @Gromix can you share the line you added to the package.json? – Gaʀʀʏ Sep 17 '13 at 19:11
  • 6
    @Garreh It's been a while, but try `npm install grunt --save-dev` from the terminal. This should add the latest version to your `package.json`. – Romain Sep 20 '13 at 13:10
  • @Gromix My issue was unsuccessfully getting grunt from a local repo. Using npm's repo in my config allowed me to install grunt correctly. – Gaʀʀʏ Sep 20 '13 at 14:08
  • 248
    Oops - had this with a newly checked out project. Just needed to do `npm install`! – poshaughnessy Oct 11 '13 at 14:14
  • 6
    nmp install - Installs the dependencies in the local node_modules folder. – poorva Dec 27 '13 at 11:27
  • I had the same problem, but the problem was that npm install wasn't working, found the solution here: https://stackoverflow.com/questions/13443526/npm-installs-all-modules-in-usr-local-lib-node-modules – Luís Bianchin Jul 25 '14 at 03:42
  • Hi Anyone please replay on below query http://stackoverflow.com/questions/39917714/grunt-how-to-keep-node-modules-folder-globally-and-use-it-in-all-project-for – HTML Oct 10 '16 at 05:42
  • if you are a exists project. maybe should execute npm install. – lingyfh Nov 10 '16 at 08:34
  • step 2. http://gruntjs.com/getting-started#working-with-an-existing-grunt-project – lingyfh Nov 10 '16 at 08:35

13 Answers13

306

I think you don't have a grunt.js file in your project directory. Use grunt:init, which gives you options such as jQuery, node,commonjs. Select what you want, then proceed. This really works. For more information you can visit this.

Do this:

 1. npm install -g grunt
 2. grunt:init  ( you will get following options ):
      jquery: A jQuery plugin
      node: A Node module
      commonjs: A CommonJS module
      gruntplugin: A Grunt plugin
      gruntfile: A Gruntfile (grunt.js)
 3 .grunt init:jquery (if you want to create a jQuery related project.).

It should work.

Solution for v1.4:

1. npm install -g grunt-cli
2. npm init
   fill all details and it will create a package.json file.
3. npm install grunt (for grunt dependencies.)

Edit : Updated solution for new versions:

 npm install grunt --save-dev
Anshul
  • 9,312
  • 11
  • 57
  • 74
  • 2
    This version must be the old one(v0.3).today I'm unintsalled it,and install the new grunt(v0.4) called Grunt-CLI.something has changed.. – Ryan Yiada Dec 18 '12 at 07:09
  • I added solution for new version also. – Anshul Dec 18 '12 at 08:06
  • 29
    Currently, `npm install grunt` installs grunt 0.3.x. You'll need to do `npm install grunt@0.4' go locally install the version of grunt needed for grunt-cli – Jack Jan 16 '13 at 01:46
  • 6
    I wish the Grunt install steps would address the @0.4. Was really wringing my hands trying to figure this out until I found your comment. – cnp Feb 07 '13 at 21:03
  • 2
    `npm install grunt --save-dev` did it for me – Vinicius Braz Pinto Aug 06 '14 at 21:00
  • 6
    `grunt-cli` should be installed globally, but it expects you to have a local install of `grunt.js` in your project. This allows each project to use a different version of grunt. I typically use npm with a package.json file to install grunt.js all any other grunt conribs etc. – Henry Oct 29 '14 at 23:54
  • Shouldn't it be "grunt grunt:init"? – Mads Skjern Mar 20 '15 at 08:51
  • 1
    npm install grunt --save-dev did the job for me. – Kiran Dash Feb 13 '16 at 07:46
189

Install Grunt in node_modules rather than globally

Unable to find local Grunt likely means that you have installed Grunt globally.

The Grunt CLI insists that you install grunt in your local node_modules directory, so Grunt is local to your project.

This will fail:

npm install -g grunt

Do this instead:

npm install grunt --save-dev
superluminary
  • 47,086
  • 25
  • 151
  • 148
86

Do

npm install

to install Grunt locally in ./node_modules (and everything else specified in the package.json file)

Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
  • 4
    I did that cause like a fool I forgot running this command after pulling the new fresh project's repo to mac..... :/ – neoswf Jun 05 '15 at 16:07
  • 2
    How come grunt needs to be installed locally since the command line tool can always be located globally? – Mike M Aug 18 '15 at 14:22
  • 1
    @MikeM sometimes you have `node_modules/.bin` in your `PATH`. Also, local and global can be different versions. – Klas Mellbourn Aug 19 '15 at 10:59
  • In my case it was NetBeans' fault. Sometimes it crashes my projects when I do `git stash` in external tool, here it removed some modules from `node_modules` and everything stopped working (and was working fine before). After `npm install` it works well again. – Wirone Oct 07 '15 at 09:05
27

If you already have a file package.json in the project and it contains grunt in dependency,

  "devDependencies": {
    "grunt": "~0.4.0",

Then you can run npm install to resolve the issue

Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
7

I made the mistake to install some packages using sudo and other without privileges , this fixed my problem.

sudo chown -R $(whoami) $HOME/.npm

hope it helps someone.

misterzik
  • 1,740
  • 1
  • 16
  • 20
5

It says you don't have a local grunt so try:

npm install grunt

(without the -g it's a local grunt)

Though not directly related, make sure you have Gruntfile.js in your current folder.

lovelikelando
  • 7,593
  • 6
  • 32
  • 50
Tomer Ben David
  • 8,286
  • 1
  • 43
  • 24
4

Could be a few problems here depending on what version of grunt is being used. Newer versions of grunt actually specify that you have a file named Gruntfile.js (instead of the old grunt.js).

You should have the grunt-cli tool be installed globally (this is done via npm install -g grunt-cli). This allows you to actually run grunt commands from the command line.

Secondly make sure you've installed grunt locally for your project. If you see your package.json doesn't have something like "grunt": "0.4.5" in it then you should do npm install grunt --save in your project directory.

3

I had to execute the following commands on ubuntu to solve this problem (I know grunt for 1 hour) :

sudo npm install -g grunt
sudo npm install -g grunt-cli

cd /usr/local/bin
# current symlink points to ../lib/node_modules/grunt/bin/grunt*
sudo rm /usr/local/bin/grunt
sudo ln -s ../lib/node_modules/grunt-cli/bin/grunt* grunt

It is dirty but it is the only one solution I found... :(

Max
  • 511
  • 8
  • 18
2

None of the above worked for me because i had grunt installed globally (recommended in several of these answers, oddly) and that was messing everything up. Here's what did work:

npm uninstall -g grunt
npm install

Only now was a local grunt installed, and useable, for me.

mlncn
  • 3,308
  • 2
  • 23
  • 20
1

Just npm install to install node_modules

Aurasphere
  • 3,841
  • 12
  • 44
  • 71
Miku Ghoul
  • 634
  • 1
  • 6
  • 7
1

You can simply run this command:

npm install grunt --save-dev
Pang
  • 9,564
  • 146
  • 81
  • 122
Vinod Kumar
  • 1,191
  • 14
  • 12
0

Being new to grunt and setting it up, I am running (perhaps foolishly) my grunt project/folder from a Google Drive so I can access the same code/builds from either my laptop or workstation.

There is a fair bit of synchronisation of the nodes_modules folders back to Google Drive and there seemed to be a conflict at some point, and the /nodes_modules/grunt folder was renamed to /nodes_modules/grunt (1)

Renaming it back by removing the (1) seemed to fix it for me.

LJT
  • 1,250
  • 3
  • 20
  • 25
  • Why don't you use GIT? – hmrc87 Jun 15 '16 at 06:13
  • I wasnt wanting to track/versions changes and was trying not to maintain two separate grunt installs, but the above scenario was fairly problematic so I have moved around to github anyway. – LJT Jun 15 '16 at 11:18
0

I had the same issue in Vagrant.

I have used sudo to run the command to install.

sudo npm install -g grunt-cli

It worked for me.

user1012513
  • 2,089
  • 17
  • 14