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:
No problem. Let’s move to the manual installation method:
- Add the NodeSource package signing key:
curl -sSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
- Set the version to node_10.x:
VERSION=node_10.x
- Let’s set the distro to
eoan
, the current stable Ubuntu version:DISTRO="eoan"
- 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
- The commands should like this in the terminal:
- We can now run
sudo apt update
to update the repository information: - We will now attempt to install the nodejs package by running
sudo apt install nodejs
:
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
- We will manually navigate to the repository to download the file here: https://deb.nodesource.com/node_10.x/pool/main/n/nodejs/
- 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: - 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
- We need to extract the
control.tar.gz
file:tar -xzf control.tar.gz
- Using nano or your favorite text editor, we will edit the
control
file. Look forpython-minimal
:nano control
- Change
python-minimal
topython2-minimal
: - Save the file. On nano, press
CTRL + O
, then exit pressingCTRL + X
. - We now need to recreate the
control.tar.gz
tar package to include the modifiedcontrol
file. To do this, we will run the following command:tar -czf control.tar.gz control md5sums postinst pr einst prerm
- 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
- We can now install the package with
dpkg
. We’ll run the following:sudo dpkg -i nodejs_10.19.0-1nodesource1_amd64.deb
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
:
And that’s it! We have successfully installed Node.js on our Ubuntu Focal installation.