66

I am trying to update npm itself:

npm uninstall npm -g

Responds with:

unbuild npm@2.12.1

But when I go:

npm --version

I get 1.4.28? How to upgrade the npm itself?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Leeuwtje
  • 2,161
  • 5
  • 21
  • 28
  • 1
    possible duplicate of [How can I update Node.js and NPM to the next versions?](http://stackoverflow.com/questions/6237295/how-can-i-update-node-js-and-npm-to-the-next-versions) – laggingreflex Jul 08 '15 at 10:46
  • It's not what you asked, but [NVM](https://github.com/creationix/nvm) solved my problems with npm installations – bluesmonk Jul 31 '18 at 18:16

3 Answers3

60

By using this command you can update npm to the latest release by using npm itself :

 npm i -g npm@latest
Hadi AJ
  • 3
  • 4
Vivek Anand
  • 1,264
  • 8
  • 15
  • NB: you may also need to upgrade node. To do that, in an elevated session run `nvm install latest` then `nvp use latest`. – JohnLBevan Feb 23 '23 at 14:46
36

You can try this:

cd /usr/lib/node_modules

npm install npm@latest

Edit:

npm install -g npm worked for me.

enter image description here

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Pratyush Khare
  • 689
  • 5
  • 16
  • You are likely using a version of node-tar or npm that is incompatible with this version of Node.js. – Anton Dec 06 '17 at 21:05
11

See which version you have

npm -v

Install the newest npm update

npm install -g npm@latest

Upgrade to the most recent release

npm install -g npm@next 

Upgrading on Windows Microsoft wrote a small command-line tool to automate the steps below. You can go and download it here

https://docs.npmjs.com/try-the-latest-stable-version-of-npm

Hamid Shoja
  • 3,838
  • 4
  • 30
  • 45