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.2.0 is the current release.

$ curl -sL | sudo -E bash -

Latest Stable Release

In this article , We are installing Node.js 12.16.3 latest stable version.

$ curl -sL | sudo -E bash -

Sample Output:

## Confirming "focal" 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 focal main' > /etc/apt/sources.list.d/nodesource.list

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

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

+ apt-get update

Get:1 focal InRelease [4583 B]

Hit:2 focal InRelease

Hit:3 focal-updates InRelease

Hit:4 focal-security InRelease

Hit:5 focal-backports InRelease

Get:6 focal/main amd64 Packages [767 B]

Fetched 5350 B in 1s (7988 B/s)

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

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) ...


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 LTS

How to Install Angular CLI on Ubuntu 18.04/16.04 LTS

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

Leave a Comment

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

Share via
Copy link