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):

  1. Create a new file: /etc/apt/sources.list.d/nodesource.list

    You’ll need to create this file with sudo, but when you create the file, put this inside it:

    deb xenial main
    deb-src xenial main

    Then, save the file.

  2. Download the GPG Signing Key from Nodesource for the repository. Otherwise, you may get NO_PUBKEY errors with apt-get update:
    curl -s | sudo apt-key add -
  3. Manually run sudo apt-get update.

    This refreshes the data from the nodesource repo so apt knows a newer version exists.

    If you get a NO_PUBKEY GPG error, then go back to Step 2

  4. Check apt-cache policy nodejs output.

    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 xenial/main amd64 Packages
        4.2.6~dfsg-1ubuntu4 500
           500 xenial/universe amd64 Packages

    If you do not see entries like this, and only see 4.2.6, start over. Otherwise, proceed.

  5. Install the nodejs binary. Now that you have confirmed 6.x is available on your system, you can install it: sudo apt-get install nodejs
  6. nodejs --version should now show v6.2.1 or similar on output (as long as it starts with v6. you’re on version 6 then).

You may also like...