How to Install Nodejs on Ubuntu 18.04

In this tutorial, we’ll explain How to Install Node.js on Ubuntu 18.04.  We will show you different methods to install Nodejs on Ubuntu 18, lets see one by one. How to Install Nodejs on Ubuntu 18.04

Prerequisite:

  • Sudo / Root access with SSH access to Ubuntu
  • Internet access to Ubuntu for downloading packages

Steps to Install Nodejs on Ubuntu 18.04

Step 1: Update the Ubuntu package index

$ sudo apt update

Step 2: Install Nodejs on Ubuntu

$ sudo apt install nodejs

Step 3: Verify nodejs installation

$ nodejs --version

Demo Output:

root@ubuntu:~# nodejs --version

v8.10.0

root@ubuntu:~#

Step 4: Install Nodejs Package Manager – npm

$ sudo apt install npm

Step 5: Verify npm installation

$ npm --version

Demo output:

root@ubuntu:~# npm --version

3.5.2

root@ubuntu:~#

Now, lets see another method to install Nodejs on Ubuntu 18.04 from NodeSource repository 

Steps to Install Nodejs on Ubuntu 18.04 from NodeSource repository

Step 1: Enable NodeSource Repository

$ sudo apt install curl -y

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

For installing the latest version follow the link as per your need.

For Node.js v10.x: 

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

For Node.js v12.x:

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

For Node.js v14.x:

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

In this blog lets install Nodejs v14x.

Step 2: Installing Nodejs and npm

$ sudo apt install nodejs

Step 3: Verify Nodejs installation

$ node --version

Demo output

root@ubuntu:~# node --version

v14.4.0

root@ubuntu:~#

Step 4: Verify npm installation

$ npm --version

you have successfully installed Nodejs from the NodeSource repository.

Install build tools

$ sudo apt-get install -y build-essential

This is optional if you need build-essential the install with above command.

Command to uninstall nodejs

$ sudo apt remove nodejs npm

End of tutorial, you have learned how to Install Nodejs on Ubuntu 18.04

Checkout all DevOps blogs