Installing Node.js 10.x on Ubuntu Focal (20.04) before the official release

Installing Node.js 10.x on Ubuntu Focal (20.04) before the official release

Hi everyone,

Today, I’ll guide you through the steps of installing Node.js 10.x on Ubuntu Focal (20.04) which is stated to be officially released on April 23, 2020.

Right now, installing Node.js using the NodeSource Node.js official repositories do not work because they do not support unreleased versions of Ubuntu.

You may think of using a previous Ubuntu repository in order to install Node.js, but this will actually not work. This is because Ubuntu 20.04 renamed the Python 2 packages from python to python2.

Trying to install Node.js using the NodeSource repositories

The easiest way to normally install Node.js 10.x is by using the official NodeSource repository. For this, we follow their steps.

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash

The problem is that because the OS hasn’t been officially released, we get the following issue:

NodeJS script failing on Ubuntu Focal 20.04

No problem. Let’s move to the manual installation method:

  1. Add the NodeSource package signing key:
    curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
  2. Set the version to node_10.x:
    VERSION=node_10.x
  3. Let’s set the distro to eoan, the current stable Ubuntu version:
    DISTRO="eoan"
  4. Now, we need to add the repository to our Linux installation:
    echo "deb https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee /etc/apt/sources.list.d/nodesource.list
    echo "deb-src https://deb.nodesource.com/$VERSION $DISTRO main" | sudo tee -a /etc/apt/sources.list.d/nodesource.list
  5. The commands should like this in the terminal:
    NodeJS Manual installation commands
  6. We can now run sudo apt update to update the repository information:
    NodeJS manual installation apt update
  7. We will now attempt to install the nodejs package by running sudo apt install nodejs:
    NodeJS installing nodejs fails

As you can see above, following the manual installation steps fails as well because there is no python-minimal package in Ubuntu 20.04. To solve this, we will manually download the Node.js Debian package and modify it to have it refer to python2-minimal instead of python-minimal.

Manually downloading, modifying and installing Node.js 10.x

  1. We will manually navigate to the repository to download the file here: https://deb.nodesource.com/node_10.x/pool/main/n/nodejs/
    NodeJS HTTP repo
  2. From there, just copy the desired Node.js package link to the clipboard. Then, use wget to download it on the terminal. I recommend downloading it to a clean directory since we will run some commands to extract and perform some modifications to it:
    Downloading the NodeJS debian package
  3. Once the download finishes, we need to extract the downloaded debian package with the ar utility:
    ar x nodejs_10.19.0-1nodesource1_amd64.deb
    extracting the NodeJS debian package
  4. We need to extract the control.tar.gz file:
    tar -xzf control.tar.gz
    Extracting control.tar.gz
  5. Using nano or your favorite text editor, we will edit the control file. Look for python-minimal:
    nano control
    Editing the control file
  6. Change python-minimal to python2-minimal:
    Renaming python-minimal to python2-minimal
  7. Save the file. On nano, press CTRL + O, then exit pressing CTRL + X.
  8. We now need to recreate the control.tar.gz tar package to include the modified control file. To do this, we will run the following command:
    tar -czf control.tar.gz control md5sums postinst pr einst prerm
    Recreating the control.tar.gz file
  9. Finally, we will replace the control.tar.gz in the debian package file. We will run the following command to do so:
    ar -r nodejs_10.19.0-1nodesource1_amd64.deb control.tar.gz
    Replacing the control.tar.gz in the NodeJS debian package
  10. We can now install the package with dpkg. We’ll run the following:
    sudo dpkg -i nodejs_10.19.0-1nodesource1_amd64.deb
    Installing the modified NodeJS debian package

After following the above steps, we should have Node.js installed on our operating system. We can confirm this by running node -v and npm -v:

Checking NodeJS and npm versions

And that’s it! We have successfully installed Node.js on our Ubuntu Focal installation.