JavaScript

How to install the latest Node.js on Linux?

Node.js is a runtime JavaScript environment that is used on the server-side. Node.js is a full-stack software building solution but is mostly used at the back end to build the applications. Node.js uses the NPM package manager as a default package manager, which is known as the most used software registry.

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.

$ sudo apt update

Then, install the Node.js using the simple apt install command with the sudo privileges.

$ sudo apt install nodejs -y

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.

$ sudo apt install npm -y

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.

$ nodejs --version

$ npm --version

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.

$ sudo apt install curl -y

After installing the curl, execute the following command to run Nodesource’s installation script using the curl command.

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

Once the NodeSource’s PPA is configured for Node.js on your system, now install the Node.js by typing the following command.

$ sudo apt install nodejs -y

Let’s verify the versions of Node.js and NPM by typing the commands.

$ node --version
$ npm --version

You can witness that the required versions are installed successfully.

Wrap up

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.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.