Peter T.
Peter T.

Reputation: 3315

Updating npm when using nvm-windows

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.

Upvotes: 74

Views: 45242

Answers (10)

Ryan Shillington
Ryan Shillington

Reputation: 25088

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\v14.20.0           # or whatever node version you're using
move npm npm-old
move npm.cmd npm-old.cmd
move npx npx-old
move npx.cmd npx-old.cmd
cd node_modules\
move npm npm-old
cd npm-old\bin
node npm-cli.js i -g npm@latest --force

And boom, upgraded.

Upvotes: 88

Yarh
Yarh

Reputation: 1098

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

Upvotes: 4

Epok98
Epok98

Reputation: 109

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.

Upvotes: 1

Nathan Smith
Nathan Smith

Reputation: 1813

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

Upvotes: 3

Jeff Kilbride
Jeff Kilbride

Reputation: 2814

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.

Upvotes: 22

Georgi Marinov
Georgi Marinov

Reputation: 91

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.

Upvotes: 7

Clayton Bell
Clayton Bell

Reputation: 430

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

Upvotes: 2

scr2em
scr2em

Reputation: 1024

This worked for me:

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

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

Upvotes: -2

sytolk
sytolk

Reputation: 7383

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

Upvotes: 7

KAUSHIK PARMAR
KAUSHIK PARMAR

Reputation: 623

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

Upvotes: 12

Related Questions