Reputation: 798
I cannot seem to update npm with npm install:
$ npm -v
5.6.0
$ sudo npm install -g npm@latest
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
+ npm@5.7.1
updated 1 package in 11.905s
$ npm -v
5.6.0
Upvotes: 20
Views: 31478
Reputation: 11
Npm will always use the version of npm installed with node. If you are running node update node first running:
$ sudo npm install -g n
And to install the latest stable node release)
$ sudo n latest
And then check your npm version again - it should be updated. Good luck! :)
Upvotes: 1
Reputation: 133
I had the same prob,
Go to your root
Run which npm and see the root, I believe it will be "/usr/local/bin/npm"
Stay on your root and try to run npm install -g npm@latest
I bet you get "missing permissions..."
Stay on your root and run the command: (to give permissions)
sudo chown -R $USER /usr/local/lib/node_modules
And then run:
npm install -g npm@latest
Now it should work, please try to run npm -v and see if it changed.
Goodluck :)
Upvotes: 0
Reputation: 191
Use hash -r
to make bash clear its cache and look at the path again for latest npm path.
Upvotes: 19
Reputation: 798
I had noted that after installing the update, I have the re-login to the shell too see the updated npm version. Not sure why some ppl don't have to do this, but in my case, that's what I had to do.
Upvotes: 9
Reputation: 23084
What's the output of your which npm
, I bet it is not /usr/bin/npm
.
UPDATE:
So yours' at /usr/local/bin/npm
, but the npm
you just updated is at /usr/bin/npm
. See the line /usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
for the hint.
Remove the installation at /usr/local/bin/npm
and you'll be fine.
If you don't know how to do that, simply do
sudo rm /usr/local/bin/npm
Upvotes: 39