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

Viewed 13621

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?

7 Answers

type 'hash -r' on your server bash.

Then check your 'npm -v' again

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

sudo npm install -g npm

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

Try this

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

@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

Related