I am using npm v5.3.0. Now I want to update npm to v5.4.1.To do this I type the following in my terminal:
npm install -g npm
without any errors.Howe
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.
I was facing the same error today. I updated node. Since npm comes bundled with node, npm was also updated but updated npm version was not reflecting. I, also, tried to update npm version by using commands npm install -g npm@latest. But, the version was not reflecting.
This is how I resolved it.
A lot of post suggested to use the command npm cache clean --f. But, it did not work for me. Hence, I deleted the "npm" and "npm-cache" folders from the location C:\Users\SearchYourUserName\AppData\Roaming
Uninstalled again the existing node.
Re-Installed node version v10.x.x. I downloaded the node-v10.22.1-x64.msi file from https://nodejs.org/dist/latest-v10.x/ and installed it.
Then checked the npm version. It had worked.
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
To upgrade, run: sudo npm install npm@latest -g
The npm module is available for download at https://registry.npmjs.org/npm/-/npm-{VERSION}.tgz.
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 npm@5.4.1
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 npm@5.4.1
again.
I had to dig a little bit more (probably I have some misconfig) and take an hardcore approach...
First I ran which npm
to get the script that was running, that was /usr/local/opt/node@8/bin/npm.js
.
From that script I saw that the npm package was actually in /usr/local/opt/node@8/lib/node_modules/npm
.
So I ran
cd /usr/local/opt/node@8/lib/
npm i npm@6.11.2 # or your desired version
rm package-lock.json # clean up
And that did the trick, hope it helps someone :)
NB: I'm not saying that you should do this right away, first is better if you try the other approaches but if other approaches are not working give it a shot