Node.js is an open-source cross-platform JavaScript runtime for easily building fast and scalable network applications.

NPM (Node Package Manager) is Node’s official package manager used for installing and managing package dependencies.

We will be installing Nodejs using Two methods, Ubuntu official repository and NodeSource repository.The same instructions can be used for installing any Ubuntu-based distribution, Linux Mint, Kubuntu and Elementary OS.

Ubuntu 18.04 contains a version of Node.js in its default repositories and to get this version, you can use the apt package manager.

Before installing nodejs, we need to update or refresh package indexing. Please run below command for the same.


$ sudo apt-get update

Output something like the below image :-

Now let’s check the two methods for installing nodejs.

Solution 1: Installing from Ubuntu Official Repository

Please run below command in your terminal window for installing nodejs


$ sudo apt-get install nodejs

Output something like the below image :-

Once nodejs installed in your system you can check the nodejs version by typing below command


$ nodejs -v

Output something like the below image :-

If you need to use npm as well then you need to install npm package separately. NPM is a Nodejs’s package manager.

Please type below in your terminal window


$ sudo apt-get install npm

Output something like the below image :-

NPM allow you to install modules and packages to use with Node.js.

Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node.

Once npm installed in your system you can check the nodejs version by typing below command


$ npm -v

Output something like the below image :-

Solution 2: Installing Using a PPA Repository:

we will require curl package for this method, therefore let first install curl on your system typing below :-


$ sudo apt-get install curl

Output something like the below image :-

Now lets add the PPA and install nodejs. Below command will add the Nodesource signing key to your system and creates an apt sources repository file.

In below image, i am installing version 12.x, you choose other versions as well, as per your need.

Type below command for adding PPA in ubuntu source repository and installing nodejs version 12.x.

#Using Ubuntu


$ sudo curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
$ sudo apt-get install -y nodejs

#using debian


$ sudo curl -sL https://deb.nodesource.com/setup_12.x | bash -
$ sudo apt-get install -y nodejs

Output something like the below image for adding PPA respository :-

Output something like the below image for installing nodejs :-

However If you need to install another version of nodejs, for example 10.x, then just change setup_12.x with setup_10.x. For example refer below commands for installing other versions of nodejs.

Node.js v14.x:


# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_14.x | bash -
apt-get install -y nodejs

Node.js v13.x:


# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_13.x | bash -
apt-get install -y nodejs

Node.js v12.x:


# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_12.x | bash -
apt-get install -y nodejs

Node.js v10.x:


# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y nodejs

# Using Debian, as root
curl -sL https://deb.nodesource.com/setup_10.x | bash -
apt-get install -y nodejs

It is recommend to use LTS release instead of current release, its good idea to use stable version. Node.js 12.x is available in LTS release.

To check which version of Node.js you have installed in your system, type:


$ nodejs -v

Output something like the below image :-

The nodejs package contains the nodejs binary as well as npm, so you don’t need to install npm separately.

To check which version of NPM you have installed in your system, type:


$ npm -v

Output something like the below screenshot :-

To compile and install native addons from npm you may also need to install build tools:

use sudo on Ubuntu or run this as root on debian


$ sudo apt-get install -y build-essential

Uninstall NodeJs and NPM

If you need or want to uninstall Node.js and npm packages, you can use the following commands:

1.) To uninstall Node.js, but keep its configuration files, type below command in your terminal window:


$ sudo apt remove nodejs
$ sudo apt remove npm

Output something like the below screenshot :-

2.) To uninstall Node.js and remove any of its configuration files, type below command in your terminal window:


$ sudo apt purge nodejs
$ sudo apt purge npm

Output something like the below screenshot :-

Previous post
How To Fix The Google GPG Error on Ubuntu
Next post
How to Setup Multiple Database Connections with Spring Boot

Write a Comment

Your email address will not be published. Required fields are marked *

All Rights Reserved. ReadAndCare