Upgrade node.js version after upgrading ubuntu 14 one-click to Ubuntu 16

October 17, 2016 56 views
Node.js One-Click Install Apps Ubuntu 16.04

I just upgraded a one-click node.js ubuntu 14.04 image to ubuntu 16.04.

The node version is v4.2.1 and the binary is located at /usr/local/bin/node. However, Ubuntu 16 comes with node v4.6.0. I discovered that there is a /usr/bin/node which is v4.6.0 on my image.

How can I remove the old node version and use the newer node version that comes with Ubuntu 16.05?

2 Answers

You can go even without removing old node, just by adding 6.x repository and updating.
If you want to remove it you can do it by executing

  • sudo apt-get remove nodejs

This is fully optional step, as you can get it working without removing.
Basically, we will install it using PPA method.

Download repo installer by executing:

  • curl -sL -o

After it downloads, you can inspect it if you want with any text editor:

  • nano

If it's OK, run it:

  • sudo bash

Let it finish.
Now you are ready to install latest Node.js. If you didn't removed Node.js, just run:

  • sudo apt-get upgrade
apt-get upgrade
root@node-512mb-nyc1-01:~# sudo apt-get -y upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
Use 'sudo apt autoremove' to remove it.
The following packages will be upgraded:
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 10.1 MB of archives.
After this operation, 37.5 MB of additional disk space will be used.

As you can see, it will upgrade your Node.js to latest. Yet, if you removed it in first step, install it with:

  • sudo apt-get -y install nodejs

That is it! You can now verify version of Node.js with:

  • node -v

At time of writing this it should output:

node -v

You can also verify npm version with:

  • npm -v

At time of writing it is:

npm -v

Hi xMudrii,

Your method does not work. The Ubuntu node.js version is upgraded to 6.8 but the older node.js remains. I think the cause of the problem lies with the PATH variable. The PATH variable is set such that the older node.js version has priority over the newer one.

I posted a new question as a follow-up to this question

I have a new problem. Would you know how to downgrade node v6.8 back to node v4.6?

Have another answer? Share your knowledge.