How to update npm

UbuntuNpm

Ubuntu Problem Overview


I'm trying to install mean.io boilerplate. It fails when running sudo npm install -g meanio@latest. Prior to failing it notes that it 'wants' npm version 1.4.x, whereas I have 1.2.18 installed. So I tried updating npm to the latest; several ways. Last of which was...

ubuntu@ip-xxx-xx-xx-xxx:~$ sudo npm install -g npm
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
npm@1.4.7 /usr/local/lib/node_modules/npm

ubuntu@ip-xxx-xx-xx-xxx:~$ npm --version
1.2.18

Why is it still showing version 1.2.18, when I just updated to 1.4.7?

Ubuntu Solutions


Solution 1 - Ubuntu

This will update npm using npm itself:

sudo npm install npm -g

If you are stuck, try sudo npm update npm -g. All credit goes to Tim Castelijns. I have tested it on ubuntu 14.04, npm 1.3.10


Note that if you are using nvm for managing multiple versions in your local dev environment for e.g. testing purposes, all your installed versions (listed by nvm ls) are in ~/.nvm, hence you just omit system wide installation (i.e. omit sudo):

npm install npm -g

DEBIAN ENTERPRISE

For full enterprise practice consider nodesource.com:

> curl -sL https://deb.nodesource.com/setup | sudo bash -

as described here.

OTHER ENTERPRISE

For non-debian distributions check out on the node github wiki https://github.com/joyent/node/wiki/installing-node.js-via-package-manager</strike> download page https://nodejs.org/en/download/

For historical understanding: Chis Lea was maintaining his PPA but now joined forces with nodesource.

Solution 2 - Ubuntu

if user3223763's answer doesn't works, you can try this:

sudo apt-get remove nodejs ^node-* nodejs-*
sudo apt-get autoremove
sudo apt-get clean
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install nodejs

Then :

curl https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | sh

After this, open a new terminal and check the npm version:

npm --version

EDIT / UPDATE :

Today the last nvm version is :

> https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh

Thus the CURL command is: v0.25.4 instead of v0.13.1

curl https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | sh

> You can check https://github.com/creationix/nvm/releases to use the correct version for further upgrades

Solution 3 - Ubuntu

don't forget to close and start the terminal window again ;)

(at least if you want to check "npm --version" in the terminal)

sudo npm install npm -g

that did the trick for me, too

Solution 4 - Ubuntu

Tried the options above on Ubuntu 14.04, but they would constantly produce this error:

> npm ERR! tar pack Error reading > /root/tmp/npm-15864/1465947804069-0.4854120113886893/package

Then found this solution online:

  1. Clean the cache of npm first:

    sudo npm cache clean -f

  2. Install n module of npm:

    sudo npm install -g n

  3. Begin the installation by selecting the version of node to install: stable or latest, we will use stable here:

    sudo n stable

  4. Check the version of node:

    node -v

  5. Check the version of npm:

    npm -v

Solution 5 - Ubuntu

Looks like you are using Ubuntu (from the command line you show). To update npm and nodejs you can use the PPA repository:

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

Solution 6 - Ubuntu

To get the latest stable version just run

npm install npm@latest -g

It worked just fine for me!

Solution 7 - Ubuntu

You can try:

sudo npm i -g npm

Solution 8 - Ubuntu

You can use npm package manager:

npm install npm@latest

This installs npm using itself @ latest version.

Solution 9 - Ubuntu

upgrading to nodejs v0.12.7

 # Note the new setup script name for Node.js v0.12
 curl -sL https://deb.nodesource.com/setup_0.12 | sudo bash -

 # Then install with:
 sudo apt-get install -y nodejs

Source from nodesource.com

Solution 10 - Ubuntu

For me It worked with following commands

  1. $curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
  2. $apt install nodejs

Refer : https://linuxhint.com/how-to-update-npm-packages/

Solution 11 - Ubuntu

NPM was returning the old version after running $ sudo npm install npm -g.

Restarting the terminal (i.e. close and open again) fixed the issue for me and $ npm --version began returning the expected version.

* @Rimian mentions the need to reload the terminal in a comment of another answer.

Solution 12 - Ubuntu

sudo npm install npm@latest -g

This worked for me in ubuntu 18.04

Solution 13 - Ubuntu

In case you want to update npm to a specific version, you can use this :

npm install npm@version-number

Solution 14 - Ubuntu

npm i -g npm

      Update available 4.5.04.6.1    │
   │     Run npm i -g npm to update 

this is what npm recommends when in terminal, second piece is directly copied and pasted from my terminal

note: im using a mac

Solution 15 - Ubuntu

Check your node version node -v and your npm version npm -v Then To update your npm, type this into your terminal : sudo npm install npm@latest -g

N.B: Debian Based OS{ubuntu or Linux mint}

Solution 16 - Ubuntu

Very simple

For Linux or Mac

sudo npm install npm@latest -g

For Windows: Run your command prompt as administrator and run the command below

npm install npm@latest -g

Solution 17 - Ubuntu

Check your node version node -v and your npm version npm -v Then To update your npm, type this into your terminal: npm install npm@latest -g

Hope I could help. Regards

Solution 18 - Ubuntu

This is what worked for me on ubuntu curl -L https://www.npmjs.com/install.sh | sh

Solution 19 - Ubuntu

nvm install-latest-npm

if you happen to use nvm

Solution 20 - Ubuntu

For Ubuntu 18.04

npm install latest-version

I hope its for you also

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3567174View Question on Stackoverflow
Solution 1 - UbuntuYauhen YakimovichView Answer on Stackoverflow
Solution 2 - UbuntuDaniel LoureiroView Answer on Stackoverflow
Solution 3 - UbuntuDaniel KettemannView Answer on Stackoverflow
Solution 4 - UbuntuKostyantynView Answer on Stackoverflow
Solution 5 - Ubuntuuser3723763View Answer on Stackoverflow
Solution 6 - UbuntuAndre PaschoalView Answer on Stackoverflow
Solution 7 - Ubuntujitendra rajputView Answer on Stackoverflow
Solution 8 - UbuntuJustin LiuView Answer on Stackoverflow
Solution 9 - UbuntuRémi BecherasView Answer on Stackoverflow
Solution 10 - UbuntuAskerali MaruthullathilView Answer on Stackoverflow
Solution 11 - UbuntuDanielView Answer on Stackoverflow
Solution 12 - UbuntuYuthies DesignersView Answer on Stackoverflow
Solution 13 - UbuntuHardieView Answer on Stackoverflow
Solution 14 - UbuntuNicholas RotondoView Answer on Stackoverflow
Solution 15 - UbuntuMd.Imam Hossain RoniView Answer on Stackoverflow
Solution 16 - UbuntuMD SHAYONView Answer on Stackoverflow
Solution 17 - UbuntuNicollasView Answer on Stackoverflow
Solution 18 - UbuntuSheshnathView Answer on Stackoverflow
Solution 19 - UbuntumuenalanView Answer on Stackoverflow
Solution 20 - Ubuntuuser2642281View Answer on Stackoverflow