npm install npm -g won't update npm to the latest version

I solved it on Ubuntu 18.04 LTS by switching to root using sudo su then I run the following

curl -L https://www.npmjs.com/install.sh | sh

The problem was that I has set the PATH variable in my ~/.profile wrong. To help you understand.I had changed npm prefix to ~/.npm-global

However I set path to ~/npm-global.So I fixed the PATH variable in my ~/.profile to point to ~/.npm-global instead.


Please try this for the latest (5.4.1) version:

npm install -g npm@latest

or for any specific version, for e.g.:

npm install -g [email protected]

If that doesn't help, go to where you have npm installed and remove the files: npm, npm.cmd.

After that please try to npm install -g [email protected] again.

Tags:

Npm