How to Install Nodejs on Ubuntu 20.04

Nodejs is a javascript runtime environment that got popular very quickly. It has got a huge developer community and is still developing very fast.

Nodejs can be installed directly from Ubuntu’s repository or can be installed from the Nodesource repository. As mentioned above it is developing very fast it is advisable to install it from the Nodesource repository as it contains all the latest updates.

We will be using the Nodesource repository to install Nodejs in this guide. Also, we will be installing the LTS version of nodejs which is 12.x currently. If you want to install the latest version you can check here for the versions available.

Let’s start installing Nodejs

Step 1: Update your OS:

Doing this is a good practice before installing any new package. Use these commands to update your system

sudo apt update
sudo apt upgrade

Step 2: Add Nodesource Repository

Good people at Nodesource have written this bash script that makes sit easier to add the repository. Download and run the script by using this command

curl -sL | sudo -E bash -

If you are installing any other version change the text marked in red with the version number in the above command.

Step 3: Install Nodejs and npm 

Use the command below to install the nodejs package. It will also install the npm package that will help you download the nodejs libraries later on.

sudo apt-get install -y nodejs

Step 4: Verify installation

If everything goes well you will have Nodejs and npm installed on your system.

To check use following commands to verify the version of both npm and nodejs installed on your system.

For nodejs:

node -v

For npm

npm -v

If everything has gone well you will see something like this

install nodejs on ubuntu

If you face any problem let me know in the comments below so we can fix the problem together.