Updating npm when using nvm-windows

node.jsWindowsNpmNvmNvm Windows

node.js Problem Overview


I'm using nvm-windows version 1.1.7.

I just installed node 11.9.0.

nvm installs npm version 6.5.0 together with this node version. However, there's npm version 6.7.0 available already.

When I now do npm i -g npm I get:

npm ERR! path C:\Program Files\nodejs\npm.cmd
npm ERR! code EEXIST
npm ERR! Refusing to delete C:\Program Files\nodejs\npm.cmd: is outside C:\Program Files\nodejs\node_modules\npm and not a link
npm ERR! File exists: C:\Program Files\nodejs\npm.cmd
npm ERR! Move it away, and try again.

I found no way to avoid this.

node.js Solutions


Solution 1 - node.js

This is a duplicate from my answer here: https://stackoverflow.com/a/50955293/491553

Here is how I upgrade npm when running nvm-windows:

cd %APPDATA%\nvm\v8.10.0           # or whatever version you're using
move npm npm-old
move npm.cmd npm-old.cmd
cd node_modules\
move npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm@latest

And boom, upgraded.

Solution 2 - node.js

Several workarounds are available in this Issue on the nvm-windows github repo:

https://github.com/coreybutler/nvm-windows/issues/300

There are examples using DOS, PowerShell, bash, and batch scripts.

Solution 3 - node.js

I have windows 10 operating system.

I installed in following way.

cd %APPDATA%\nvm\v8.11.3
move npm 5.6.0
move npm.cmd 5.6.0.cmd
cd node_modules\
move npm 5.6.0
cd 5.6.0\bin
node npm-cli.js i -g npm@latest

Solution 4 - node.js

I had to force it :-/

When it came to

node npm-cli.js i -g npm@latest

I'd rather had to use

node npm-cli.js i -g npm@latest --force

probably to overcome a permission error involved in overwriting the "C:\Program Files\nodejs" link.

Solution 5 - node.js

  1. download this updateNpm.bat file
  2. open powershell in that same folder and run this command updateNpm.bat latest

Solution 6 - node.js

I also found it necessary to install windows-nvm to c:\nvm and c:\nodejs to prevent issues with unsupported paths with spaces.

rm C:\nodejs\npm*
rm C:\nodejs\npx*
mv C:\nodejs\node_modules\npm C:\nodejs\node_modules\npm-old
node C:\nodejs\node_modules\npm-old\bin\npm-cli.js i -g npm@next

Solution 7 - node.js

For me I only get the problem when updating npm with npm v6.
So using a newer version of npm via npx to run the upgrade works for me.

For the very newest version
npx npm install -g npm

Or use a specific version
npx npm@7 install -g npm@7

Solution 8 - node.js

I faced this problem today, the way i solved it was installing latest node with nvm then copying the npm files from latest to the version i am on.

nvm install latest
cd AppData/Roaming/nvm/LATEST
xcopy npm.cmd ../LTS && xcopy npm ../LTS && xcopy node_modules/npm ../LTS

I then confirmed it working by trying to compile my code that breaks on latest.

Solution 9 - node.js

I tried the script and other solutions, this by far is the easiest way:

  1. Navigate to the relevant Node folder (cd C:\Users\yourUser\AppData\Roaming\nvm\vxx.xx.x)
  2. rename npm -> npm2
  3. rename npm.cmd -> npm2.cmd
  4. rename npx -> npx2
  5. rename npx.cmd -> npx2.cmd
  6. Run npm2 install -g npm@your-version
  7. the new npm will create npm, npm.cmd, npx, npx.cmd files, so you can remove the previous renamed files

Solution 10 - node.js

This worked for me:

curl -L https://npmjs.org/install.sh | sh

If you already have git bash installed, use it there.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPeter T.View Question on Stackoverflow
Solution 1 - node.jsRyan ShillingtonView Answer on Stackoverflow
Solution 2 - node.jsJeff KilbrideView Answer on Stackoverflow
Solution 3 - node.jsKAUSHIK PARMARView Answer on Stackoverflow
Solution 4 - node.jsGeorgi MarinovView Answer on Stackoverflow
Solution 5 - node.jssytolkView Answer on Stackoverflow
Solution 6 - node.jsClayton BellView Answer on Stackoverflow
Solution 7 - node.jsNathan SmithView Answer on Stackoverflow
Solution 8 - node.jsSoloOrchidView Answer on Stackoverflow
Solution 9 - node.jsYarhView Answer on Stackoverflow
Solution 10 - node.jsscr2emView Answer on Stackoverflow