There are several methods to install Node.js on Ubuntu 20.04 LTS, but here, we will learn the two most efficient and easiest methods to install it.
- Using APT package repository
- Using the APT package repository through NodeSource PPA
Let’s get started with the easiest one.
Install Node.js on Ubuntu 20.04 using APT
Installing any software through the APT package repository is the easiest way to install the software on Ubuntu. First, update the system’s package repository.
Then, install the Node.js using the simple apt install command with the sudo privileges.
In this command, the “-y” flag is added to automatically answer “yes” if any prompt occurs.
After installing the Nodejs, if you want to install NPM as well, run the command.
After a while, NPM will be installed as well.
The above two commands will install all the other tools required for compilation.
To verify and check the versions of the Node.js and NPM, execute the following two commands.
As you can see, version 10.19.0 of Node.js and version 6.14.4 of NPM is installed.
Install Node.js on Ubuntu 20.04 through NodeSource PPA
In case you want to install some specific or older version of Node.js, it is better recommended that you use the official Private Package Archive(PPA) managed by the NodeSource.
At the date of writing this post, NodeSource has the following Node.js versions available:
- Node.js v15.x
- Node.js v14.x
- Node.js v12.x
- Node.js v10.x
Furthermore, you can check the version provided by the NodeSource by visiting their Github page (GitHub – nodesource/distributions: NodeSource Node.js Binary Distributions).
For example, to install the Node.js v15.x, you first need to have the curl installed on your system.
To install curl, perform the following.
After installing the curl, execute the following command to run Nodesource’s installation script using the curl command.
Once the NodeSource’s PPA is configured for Node.js on your system, now install the Node.js by typing the following command.
Let’s verify the versions of Node.js and NPM by typing the commands.
You can witness that the required versions are installed successfully.
These are the two different methods to install Node.js on Ubuntu 20.04 LTS. You can either install it via the APT package repository, which is the easiest way, or go with your desired version with the official PPA introduced by NodeSource.