56

I'm having a problem running Grunt from the command line on my Windows 8 machine.

My research indicates the most common solution is to install grunt-cli, since Grunt is no longer global. I also need to make sure I actually install the Grunt task runner, since that's not installed with grunt-cli.

Other solutions point to the PATH system environment variable, but that appears to be pointed as I'd expect to:

C:\Users[username]\AppData\Roaming\npm

Having done all that, I'm still getting a "'grunt' is not recognized as an internal or external command, operable program or batch file" error message in the CLI. I've tried the following things, uninstalling everything after every attempt:

  • Installed grunt-cli globally (npm install -g grunt-cli), then grunt at the directory level I want to use it (npm install grunt)
  • The same as above, but with the order of installation reversed
  • The same as both of the above, but using the Admin Command Prompt

Am I missing something obvious?

Daniel Attfield
  • 2,024
  • 2
  • 24
  • 40
  • 8
    After `npm install -g grunt-cli`, type `where grunt`. What's the output? – WiredPrairie Oct 02 '13 at 11:56
  • @WiredPrairie: INFO: Could not find files for the given pattern(s). – Daniel Attfield Oct 02 '13 at 12:09
  • 1
    Is `grunt.cmd` located in your `AppData\Roaming\npm` folder? – WiredPrairie Oct 02 '13 at 12:14
  • Yeah, I have the grunt.cmd file in there, along with a node_modules directory and file named grunt of type FILE. When I install other modules (such as express), that's where they end up too. – Daniel Attfield Oct 02 '13 at 12:18
  • Did you open a new command window and confirm your path is correctly set? – WiredPrairie Oct 02 '13 at 12:19
  • I've used separate command windows for everything, and did confirm the path by using the 'npm config set prefix' command. – Daniel Attfield Oct 02 '13 at 12:21
  • 2
    One last try -- please confirm your PATH is correct (and not messed up). Just type `PATH` from the command prompt. There's really no other explanation that makes sense given the error you're describing and the steps. – WiredPrairie Oct 02 '13 at 12:24
  • I've just discovered the issue; the PATH list, which is usually semicolon-separated, was incorrectly comma-separated. I'm not sure why, as I didn't add this manually, but having replaced the comma with a semi-colon it seems to work. @WiredPrairie - if you add an answer I'll mark it as accepted. – Daniel Attfield Oct 02 '13 at 12:33
  • 3
    In Windows 7, I tried to set `NODE_PATH` = to `%AppData\npm` which translates to the correct path. Then, in my `Path`, I added `%NODE_PATH%` and that did not work. I think it didn't like the variable containing another variable. Meaning that in DOS I could not `cd %NODE_PATH%` but `cd %AppData%\npm` worked just fine. So I ended up just adding the complete path in my `System` variable to `npm` and moved on. Works now. – cbmeeks Apr 03 '14 at 19:50
  • This might be related to [this issue](https://github.com/joyent/node/issues/4228), posting it here in case the connection to Active Directory or non-admin users is relvant for anybody. – launchoverit Jul 01 '15 at 18:42
  • 1
    @cbmeeks, your `NODE_PATH` variable is wrong; you wrote `%AppData\npm` and it should be `%AppData%\npm` – mejdev Sep 26 '15 at 20:29
  • @Vi3GameHkr thanks for the comment but my original comment was actually a typo. I did, in fact, have the correct version you mentioned. I just typed it wrong in my comment. – cbmeeks Sep 29 '15 at 12:33

11 Answers11

63

I've not had any issues with grunt on several different windows 8 machines.

If you open the folder: C:\Users\[username]\AppData\Roaming\npm

Do you have a file named grunt.cmd in this folder?

If not I'd maybe try npm install -g grunt-cli again, maybe from an elevated command prompt.

If this exists and you have C:\Users\[username]\AppData\Roaming\npm in your PATH environment variable then typing grunt from a command prompt should work.

Silly question, have you tried closing the command prompt and opening a new one?

dKen
  • 3,078
  • 1
  • 28
  • 37
Rik Leigh
  • 1,318
  • 1
  • 7
  • 7
  • I have the grunt.cmd file in there, along with a node_modules directory and file named grunt of type FILE. I've tried with several different command prompts, both regular and administrator. I've now also tried installing something else (express), but get the same problem, so I don't think it's a Grunt issue, rather an npm problem. – Daniel Attfield Oct 02 '13 at 12:14
  • It's not an npm problem, as it's storing the files correctly, according to what you've provided. Windows can't find the file. – WiredPrairie Oct 02 '13 at 12:23
  • 2
    if you open a command prompt at C:\Users\[username]\AppData\Roaming\npm and then run grunt does it work? – Rik Leigh Oct 02 '13 at 12:25
  • 1
    I had to run the cmd windows as admin install both grunt and grunt-cli and then add the C:\Users\[username]\AppData\Roaming\npm to my PATH variable. It worked fine after that. – Andy Allison Oct 17 '13 at 09:09
  • This is what worked for me. There wasn't any grunt.cmd, then after I ran the command, it was created. Thank you – Shad Oct 06 '14 at 20:26
  • my grunt command worked as my grunt.cmd was missing and as suggested I ran the grunt-cli installation command again and this time grunt.cmd was created. It works fine now. Thanks NOTE: I ran this grunt-cli install command from inside roaming/npm directory from an elevated command prompt. – Meer Nov 05 '14 at 21:21
37

Confirm your PATH is correct (and not messed up). Just type PATH from the command prompt. There's really no other explanation that makes sense given the error you're describing and the steps you've taken.

Normally, using the where grunt command would have found grunt.cmd in your path if npm is installed correctly and it has been properly added to the system path.

WiredPrairie
  • 58,954
  • 17
  • 116
  • 143
  • 2
    The current NodeJS 64-bit version for Windows has screwed up the PATH on install. I uninstalled the 64-bit version and installed the x86 version instead and now everything just works as expected. – Rebecca Dec 18 '13 at 21:22
  • 10
    Actually it is not the PATH that is screwed up, it's the location to which it is installed. Nodejs installs itself in C:\Program Files\nodejs, but installs all modules in C:\Users\Username\AppData\Roaming\npm – Nico Apr 20 '14 at 22:24
  • 2
    `C:\Users\Username\AppData\Roaming\npm` was gone again from the PATH!!! and after i added it again i was added it worng like that `\C:\Users\Username\AppData\Roaming\npm` with extra slash on the start – ygaradon May 14 '14 at 11:42
  • +1 for "Confirm your PATH is correct (and not messed up)". When I checked the PATH variable node and the node directory were wrapped in quotes. Removing those quotes fixed the command-not-found issue for me. – worc Sep 20 '14 at 15:24
  • 2
    My PATH variable had exceeded the maximum length and so the npm path had been removed at some point by something. Shortened some of the paths using Rapid Environment Editor and all is good again! – ProNotion Jan 22 '15 at 14:44
  • Another Confirm here... For me it was a double semicolon somewhere in the path (actually at the beginning of what I can configure through advanced system settings, but somewhere in the middle of the whole path) – Tarulia Jun 15 '15 at 07:08
  • Note: for me, changing the path in command prompt with `path=%PATH%;%APPDATA%\npm` only worked temporarily, after logging out and back in the changes were lost. I had to use the GUI (Start>[Search for "Edit Environment Variables for your Account"]) and add `;C:\Users\[username]\AppData\Roaming\npm` to the PATH variable there. My setup: Windows Server 2012 R2 and running it as a user. – launchoverit Jul 01 '15 at 18:38
16
  1. Close all Command Prompt instances.
  2. Start a new Command Prompt instance.
  3. Type PATH Enter and verify if C:\Users\Username\AppData\Roaming\npm is part of the path.
  4. If not, you need to log off and on again,
    or close the Command Prompt and restart the explorer process.
  5. In the Command Prompt, type where grunt Enter.
    You're good if it reports:

    C:\Users\Username\AppData\Roaming\npm\grunt
    C:\Users\Username\AppData\Roaming\npm\grunt.cmd
    
  6. Otherwise, you have to reinstall the grunt-cli package if it reports:

    INFO: Could not find files for the given pattern(s).
    

Apparently, programs that change the PATH environment variable must broadcast a WM_SETTINGCHANGE message. The Windows' System settings window does it correctly when you change the PATH variable, but the NPM installer doesn't. That's why you have to restart explorer (or log off or restart, which has the same effect).

Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
7

I know this has been answered but I thought I'd offer my step by step solution for windows 8.

First thing I checked was the PATH in my laptops Environment Variables (Right click my computer > properties > advanced system settings > Environment Variables)

It wasn't listed in there so I added a new variable in User variables (so it was specific only to my user account)

In the new user variable prompt I entered the following;

Variable Name: PATH

Variable Value: %USERPROFILE%\AppData\Roaming\npm

Quit command prompt, repoened, navigated to my projects directory and tried running grunt again and... SUCCESS!

Tom Gillard
  • 575
  • 5
  • 21
5

I had the same issue.

I tried different things:

  • Restart computer
  • Deleted the grunt folder and ran

npm install -g grunt -cli

Didn't work.

Finally tried:

npm install -g grunt-cli

Worked perfectly.

Tried

where grunt

and I saw 2 locations where it was found.

jsan
  • 733
  • 11
  • 26
  • 3
    I lost an hour of my life thanks to that one extra tap on the spacebar. I'd up-vote again if I could. – iandayman Feb 12 '15 at 22:31
4

I was facing the same problem on windows 8

I have added ' %APPDATA%\npm ' to the path variable . It has been working fine.

JP Bala Krishna
  • 141
  • 1
  • 3
1

some times NPM install corrupts the basic windows path. i usually have a copy of my own version of PATH mainted separately. every week or on some installs i manually configure and update the %PATH% variable.

Basically Grunt.cmd is not availbe through %PATH% variable.

kadalamittai
  • 2,076
  • 1
  • 16
  • 19
1

I have stucked with problem on Windows 8, that after install grunt-cli I've always got "command not found" while I'm tried to check grunt -v or where grunt. So I've added to enviroment PATH this path C:\Program Files (x86)\Git\local and run grunt.cmd from that folder (you need to look in node_modules folder here). And after reloading my terminal everything started to work.

Chekit
  • 81
  • 1
  • 6
1

Same happened to me and here was the solution: Have you got 2 different versions of Node.JS installed? Maybe Nodist? This means you likely got NPM installed twice which will install the commands into 2 different folders: Once into C:\Users\<user>\AppData\Roaming\npm and once into C:\dev\nodist\bin\bin.

C:\dev\nodist\bin\bin wasn't on my path variable so I added it, and I removed the Node.JS version I didn't want to use.

sebbulon
  • 613
  • 7
  • 21
0

If you have no grunt.cmd file created by npm, make sure that you do not have a .npmrc in your home directory with: bin-links=false in it.

winblood
  • 1
  • 1
0

After getting a tonne of "'grunt' is not recognized as an internal or external command," errors, I solved this on Windows 10 by going to Path and adding C:\Users\Username\AppData\Roaming\npm

tedtrux
  • 201
  • 2
  • 3