Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 685
Peter T. Avatar asked Feb 12 '19 14:02

Peter T.


People also ask

Can NVM update npm?

nvm now has a command to update npm. It's nvm install-latest-npm or npm install --latest-npm .

How can I change the version of npm using NVM?

You can downgrade the npm version by specifying a version in the related commands. If you want to downgrade npm to a specific version, you can use the following command: npm install -g npm@[version. number] where the number can be like 4.9. 1 or 8 or v6.


4 Answers

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.

like image 65
Ryan Shillington Avatar answered Oct 24 '22 02:10

Ryan Shillington


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.

like image 36
Jeff Kilbride Avatar answered Oct 24 '22 02:10

Jeff Kilbride


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
like image 10
KAUSHIK PARMAR Avatar answered Oct 24 '22 03:10

KAUSHIK PARMAR


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.

like image 7
Georgi Marinov Avatar answered Oct 24 '22 02:10

Georgi Marinov