How to Install Node.js and NPM on Ubuntu 20.04 LTS

In this article, We are going to perform How to Install Node.js and NPM on Ubuntu 20.04 LTS and any other cloud platform like Azure, EC2, Compute Engine.


Node.js is free and an open-source cross-platform JavaScript run-time environment that allows server-side execution of JavaScript code. It is used in developing web and networking applications.NPM(Node Package Manager) is command line tool for Node.js packages that installs, updates and uninstall packages in your projects.We don’t have install npm separately it is includes with Node.js installation.


  • Ubuntu 20.04 LTS
  • SSH access with sudo privileges
  • Firewall Port: 3000
Before installing,Lets update and upgrade System Packages
sudo apt-get update
sudo apt-get upgrade

Step #1: Add Node.js and npm from NodeSource Repository

Before installing, We have to install curl and add Node.js from Nodesource repository.
sudo apt-get install curl

Current Release

Node.js 14.10.1 is the current release.
curl -sL | sudo -E bash -

Latest Stable Release

In this article , We are installing Node.js 12.18.3 latest stable version.
curl -sL | sudo -E bash -
Sample Output:
## Installing the NodeSource Node.js 12.x repo...

## Populating apt-get cache...

+ apt-get update
Ign:1 xenial/mongodb-org/3.6 InRelease
Hit:2 xenial/mongodb-org/3.6 Release
Hit:3 bionic InRelease
Hit:5 bionic InRelease
Get:6 bionic-updates InRelease [88.7 kB]
Get:7 bionic-security InRelease [88.7 kB]
Get:8 bionic-backports InRelease [74.6 kB]
Fetched 252 kB in 1s (221 kB/s)
Reading package lists... Done

## Confirming "bionic" is supported...

+ curl -sLf -o /dev/null ''

## Adding the NodeSource signing key to your keyring...

+ curl -s | apt-key add -

## Creating apt sources list file for the NodeSource Node.js 12.x repo...

+ echo 'deb bionic main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src bionic main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Ign:1 xenial/mongodb-org/3.6 InRelease
Hit:2 xenial/mongodb-org/3.6 Release
Hit:4 bionic InRelease
Hit:5 bionic InRelease
Hit:6 bionic-updates InRelease
Hit:7 bionic-security InRelease
Hit:8 bionic-backports InRelease
Reading package lists... Done

## Run `sudo apt-get install -y nodejs` to install Node.js 12.x and npm
## You may also need development tools to build native addons:
sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
curl -sL | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn

Step #2: How to Install Node.js and NPM on Ubuntu 20.04 LTS

Once repository added in ubuntu,enter below command to install Node.js and NPM.
sudo apt-get install -y nodejs

Step #3: Check Node.js and NPM Version on Ubuntu

After installation, check Node.js version by entering below command,
node --version
$ node --version
To Check NPM version.
npm --version
$ npm --version

Step #4: Testing Node.js Server

Create a javascript file with name nodeapp.js, add below code which prints ” Hello World”.
sudo nano nodeapp.js
Paste the below lines into it.
const http = require('http');

const hostname = '';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');

  server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
Run your Node.js server with the below command,
node nodeapp.js
$ node nodeapp.js

Server running at
Now open your browser and type server name or IP followed by port 3000, you will see Hello World message.
We have successfully covered, How to Install Node.js and NPM on Ubuntu

Installing Node.js and NPM using NVM

Download the NVM installation script from NVM GitHUB Page using curl.
curl -sL -o
once downloaded, run the bash script
It will install your system’s home directory ~/.nvm  and adds configuration in ~/.profileLoad the profile
source ~/.profile
To check all available node.js versions
nvm ls-remote
Sample output:
v12.14.0 (LTS: Erbium)
v12.14.1 (LTS: Erbium)
v12.15.0 (LTS: Erbium)
v12.16.0 (LTS: Erbium)
v12.16.1 (LTS: Erbium)
v12.16.2 (LTS: Erbium)
v12.16.3 (LTS: Erbium)
v12.17.0 (LTS: Erbium)
v12.18.0 (LTS: Erbium)
v12.18.1 (LTS: Erbium)
v12.18.2 (LTS: Erbium)
v12.18.3 (Latest LTS: Erbium)
Error: npm update check failed try running with sudo or get accesschange the permission to install node.js
sudo chown -R $USER:$(id -gn $USER) /home/ubuntu/.config
Now you can install node.js version as you want.
nvm install 12.18.3
To set recently node.js version
nvm use 12.18.3
chaeck the node varsion
node -v
check the nvm version
nvm --version
We have performed ,How to Install Node.js and NPM on Ubuntu 20.04 LTS.

Uninstall Node.js and NPM in Ubuntu

If we want to uninstall/remove node.js and npm from ubuntu, Enter Y to proceed uninstallation.
$ sudo apt remove nodejs npm
$ sudo apt remove nodejs npm
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'npm' is not installed, so not removed
The following packages will be REMOVED:
0 upgraded, 0 newly installed, 1 to remove and 84 not upgraded.
After this operation, 76.5 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 143850 files and directories currently installed.)
Removing nodejs (12.16.3-1nodesource1) ...
Processing triggers for man-db (2.7.5-1) ...
Conclusion:In this article, We have performed ,How to Install Node.js and NPM on Ubuntu 20.04 LTS, Checked Node.js and NPM version and performed to uninstall node.js and NPM from ubuntu.Related Articles:How to Install Latest Node.js and NPM on Ubuntu 19.04,18.04/16.04 LTSHow to Install Angular CLI on Ubuntu 18.04/16.04 LTSHow to Install node.js on Mac OSHow to Install Node.js on Windows 10
Aniruddha Kanade

I am Shivdas Kanade working as Senior Site Reliability Engineer (Cloud and DevOps ). Believes in Sharing Knowledge.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link