Installing Node.js 9 to Ubuntu 17.04


Unfortunately, official installing Node.js via package manager documentation has instructions only for LTS Node.js versions. Here I'll share my experience of troubleshooting Node.js installation.

First of all, official installing Node.js via package manager now contains instructions to install Node.js 8 LTS only:

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

OK, I thought, we can hack the URL and try to execute this commands:

[email protected]:~$ curl -sL | sudo -E bash -

## Installing the NodeSource Node.js v9.x repo...

## Populating apt-get cache...

+ apt-get update
...output of apt-get update here...

Actually, it works (maybe that's where your installation should over, no troubleshooting required).

Troubleshoouting my case

Installation script was downloaded and executed, but in my case nodejs was not updated:

[email protected]:~$ sudo apt-get install nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
nodejs is already the newest version (6.11.5-1nodesource1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Then I decided to dig deeper, I have downloaded script and see what it does. I found a few of useful commands there:

NODENAME="Node.js v9.x"
DISTRO=$(lsb_release -c -s)
# print_status "Confirming \"${DISTRO}\" is supported..."
curl -sLf '${NODEREPO}/dists/${DISTRO}/Release'
# print_status 'Adding the NodeSource signing key to your keyring...
curl -s | apt-key add -
# print_status "Creating apt sources list file for the NodeSource ${NODENAME} repo..."
echo 'deb${NODEREPO} ${DISTRO} main' > /etc/apt/sources.list.d/nodesource.list
echo 'deb-src${NODEREPO} ${DISTRO} main' >> /etc/apt/sources.list.d/nodesource.list
# print_status 'Running `apt-get update` for you...'
apt-get update

Each print_status should write line to console. In my case there was only two lines (Installing the NodeSource Node.js v9.x repo and Populating apt-get cache...).

It turns out that apt-get update command on this last step fails. Actually, I had several warnings and 404 errors while execution of this command.


So, there was two ways to fix: - remove any errors while executing apt-get update command (turn off bad repository feeds) - or manually execute all the necessary commands

I selected the second way. I just have added NodeSource signing key:

curl -s | sudo apt-key add -

Then I have added following lines to /etc/apt/sources.list.d/nodesource.list via editor:

deb zesty main
deb-src zesty main

(note zesty is the name of Ubuntu distributive, you can get this value using lsb_release -c -s command).

Now I was prepared to installation of Node.js:

sudo apt-get update
sudo apt-get upgrade -V

Happy coding!