How to install the latest version of NodeJS on Ubuntu 16.04
I found this great tutorial on how to install a version of NodeJS above 4.6 on Ubuntu 16.04. I was having problem with this so check THIS link or just do the steps from below.
Here’s the manual way of making this work, and it is basically what the script does (except for Step 4, which is to make sure you are getting accurate version data):
- Create a new file:
You’ll need to create this file with
sudo, but when you create the file, put this inside it:
deb https://deb.nodesource.com/node_6.x xenial main deb-src https://deb.nodesource.com/node_6.x xenial main
Then, save the file.
- Download the GPG Signing Key from Nodesource for the repository. Otherwise, you may get
curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
- Manually run
sudo apt-get update.
This refreshes the data from the nodesource repo so
aptknows a newer version exists.
If you get a
NO_PUBKEYGPG error, then go back to Step 2
apt-cache policy nodejsoutput.
This is not done by the script, but you want to make sure you see an entry that says something like this in the output:
Version table: 6.2.1-1nodesource1~xenial1 500 500 https://deb.nodesource.com/node_6.x xenial/main amd64 Packages 4.2.6~dfsg-1ubuntu4 500 500 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages
If you do not see entries like this, and only see 4.2.6, start over. Otherwise, proceed.
- Install the
nodejsbinary. Now that you have confirmed 6.x is available on your system, you can install it:
sudo apt-get install nodejs
nodejs --versionshould now show
v6.2.1or similar on output (as long as it starts with
v6.you’re on version 6 then).