7
votes
  1. Installed node.js v0.10.29 with .msi (includes npm v1.4.14)
  2. npm install -g npm (updating npm to v1.4.20)
  3. npm -v: v1.4.14 (located in c:\Program Files\nodejs\node_modules\npm)
  4. npm v1.4.20 is located in c:\Users\User\AppData\Roaming\npm\node_modules\npm
  5. echo %path:

    C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs;C:\Ruby200-x64\bin;C:\python27

    • Removing the bold part leaves me with sh.exe": npm: command not found
    • Adding %AppData%\npm\node_modules doesn't fix it

6. Adding NODE_PATH to system wide environment variables with %AppData\npm\node_modules is not helping

The problem is essentially that it refuses to recognize the global npm installation in %AppData%\npm\node_modules even when I remove C:\Program Files\nodejs from the path and replace it with %AppData%\npm\node_modules.

What am I doing wrong? How do I fix this?

4
You're not doing anything wrong. It's because computers suck.pabrams

4 Answers

5
votes

After opening this issue on joyent/node, this reply suggests using the Node.js command prompt as a temporary workaround.

Preparation:

  • Remove C:\Program Files\nodejs from any environment variables
  • Add a environment variable called NODE_PATH with this value: %AppData%\npm\node_modules
  • Check your .npmrc file (Windows: C:\Users\[User]\.npmrc)

    If the value for prefix is c:\Program Files\nodejs, add prefix = c:\Users\[User]\AppData\Roaming\npm to the user config area (at the top of the file)

After this:

  1. Start Menu > All Programs > Node.js > Node.js command prompt
  2. npm -v: 1.4.14
  3. npm install -g npm
  4. npm -v: 1.4.21
3
votes

First of all, a safe and error free node.js on windows, can be achieved if you install it in "C:\nodejs\" instead of installing it in ProgramFiles or any other directory because of some read/write permissions.

For the question...

go to cmd and run

npm install -g npm

and copy "npm" folder from

C:\Users\\AppData\Roaming\npm\node_modules\npm\node_modules

//first npm is the installed version and then npm modules are its
// modules installed one of them is your new npm that is the result
// of above command. we are copying it to its insaller. the father :P

Paste this copied "npm" folder into this path and overwrite if it asks

 C:\Program Files\nodejs\node_modules

check your verison it will be latest. by

npm -v //in cmd
2
votes

If using Windows 7 or later, try:

move "C:\Program Files\nodejs\node_modules\npm" "C:\Program Files\nodejs\node_modules\npm.bak"
mklink /D "C:\Program Files\nodejs\node_modules\npm" "%AppData%\npm\node_modules\npm"
1
votes

Check your path environment variable. My guess is that it lists both the program files and the appdata directories, and the program files location is listed first. The first one found on the path is the one that will run.