Why only outdated version of NPM is available on Debian/Ubuntu?
Asked Answered
T

7

17

I'm using a Debian/Ubuntu based distribution (specifically, AWS Ubuntu 16.04) and trying to install NPM through apt-get.

My Angular 2 application needs a higher version than 3.9.x of NPM, but the default version which is getting installed is 3.5.2 using sudo apt-get install npm on AWS Ubuntu 16.04. I'm trying to update NPM, but it's not getting upgraded to 4.6.1 (latest) from 3.5.2.

How do I install/update NPM so that I've got the latest version?

Tannie answered 21/5, 2017 at 10:53 Comment(0)
S
13

You're getting version 3.5.2 of npm, because that's the version in the repositories. Debian and Ubuntu are typically terrible at keeping up with Node and npm's fast rate of development, so you'll often find the packages are out of date, and aren't much use to you.

Some Debian distributions (e.g. Jessie) only have npm v1.4.21, which is even more out of date. Incidentally, Debian Jessie is the version upon which Raspbian Jessie, the RPi distribution, is based.

Instead, follow the instructions given on the Node.js website:

Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository (formerly Chris Lea's Launchpad PPA). Support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions.

NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros.

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Alternatively, for Node.js v7:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

The nodejs package provided by NodeSource includes npm. Simply install that, and you'll be ready to go with the latest version.

Signorelli answered 21/5, 2017 at 11:0 Comment(2)
I don't think they are terrible at updating every package. I wonder if the node and v8 code is easy to audit etc..Isopropanol
thanks, i used https://deb.nodesource.com/setup_15.xNewsboy
G
17

type 'hash -r' on your server bash.

Then check your 'npm -v' again

Garrick answered 30/1, 2019 at 20:53 Comment(3)
Thank you Sir, I for one was going insaneFreddiefreddy
This was it. Totally going insane.Quaternary
This worked, however do you have an explication as to why? It updated the symbolic link in /usr/local/bin/npm to ../lib/node_modules/npm/bin/npm-cli.js but how did it know to do so, or what was wrong?Director
S
13

You're getting version 3.5.2 of npm, because that's the version in the repositories. Debian and Ubuntu are typically terrible at keeping up with Node and npm's fast rate of development, so you'll often find the packages are out of date, and aren't much use to you.

Some Debian distributions (e.g. Jessie) only have npm v1.4.21, which is even more out of date. Incidentally, Debian Jessie is the version upon which Raspbian Jessie, the RPi distribution, is based.

Instead, follow the instructions given on the Node.js website:

Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository (formerly Chris Lea's Launchpad PPA). Support for this repository, along with its scripts, can be found on GitHub at nodesource/distributions.

NOTE: If you are using Ubuntu Precise or Debian Wheezy, you might want to read about running Node.js >= 6.x on older distros.

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

Alternatively, for Node.js v7:

curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs

The nodejs package provided by NodeSource includes npm. Simply install that, and you'll be ready to go with the latest version.

Signorelli answered 21/5, 2017 at 11:0 Comment(2)
I don't think they are terrible at updating every package. I wonder if the node and v8 code is easy to audit etc..Isopropanol
thanks, i used https://deb.nodesource.com/setup_15.xNewsboy
D
7

Upgrade npm:

$ sudo npm install -g npm@latest

$ reboot

$ npm -v

Complete installation:

$ sudo apt install nodejs

$ sudo apt install npm

$ npm -v

npm version: 3.5.2

Then upgrade:

$ npm install -g npm@latest

$ reboot

$ npm -v
Defelice answered 3/12, 2019 at 11:4 Comment(1)
'hash -r' in your shell is enough instead of a reboot.Duane
O
2

sudo npm install -g npm

Was what worked for me, I then needed the answer provided by @StefanBob

Oxime answered 6/6, 2019 at 10:20 Comment(0)
A
2

Try this

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Agnella answered 27/3, 2020 at 18:52 Comment(1)
wow this works. can you explain the n and why force cache clean and n stable does the trick??Protostele
W
0

I've read this answer and it helped me on this issue:

https://askubuntu.com/questions/1036278/npm-is-incorrect-version-on-latest-ubuntu-18-04-installation

I hope it helps you aswell.

$ sudo apt-get install npm
(...apt installation of npm was successful...)
$ npm -v
3.5.2
$ command -v npm
/usr/bin/npm
$ sudo npm install -g npm
(...npm installation of npm was successful...so far, so good)

After that, just restart the bash or follow krubo's steps.

Weatherman answered 24/9, 2019 at 10:25 Comment(0)
P
0

@Nyakwar Dayo's solution worked for me.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

But the nodejs package was installed at a different path and I manually deleted the old package (in /usr/bin/) and added a symlink to point to the new one (in /usr/local/bin).

sudo rm /usr/bin/node
sudo ln -s /usr/local/node /usr/bin/node

This is the initial printouts from running the commands. The npm version updates from 5.8.0 to 8.1.2. But the nodejs version stayed at 10.24.0 even after reboot with hash -r.

bash-ss

Protostele answered 8/1, 2022 at 2:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.