Install Nodejs on Ubuntu 18.04 Linux.

Hi Techies! Let’s learnĀ “How to Install Nodejs on Ubuntu 18.04 Linux”. It is an Open Source and cross-platform Application means that it can be run on various platforms like Linux, Windows, Mac, and many other Operating Systems like this.

Because it’s Highly Scale-able and can handle more requests than any other programming language. The biggest giant Industries like Walmart, PayPal, Netflix, etc. using Node JS.

Then in 2010, they got their Node Package manager (NPM), which is one of the largest package registries in today’s world. If you want to learn more about Node.js then follow the link.

So, we are going to install Nodejs on Ubuntu 18.04 with 3 methods.

  1. Installation of Node JS by using the apt command.
  2. Will Use PPA (personal package archive) to Install Nodejs on Ubuntu 18.04.
  3. Installing Node Using the NVM (Node Version Manager) on Ubuntu 18.04.

Requirement

So the requirement is like, we want Ubuntu 18.04 installed System, If you have to Install Ubuntu 20.04 on Host Machine or to install Ubuntu 20.04 on Virtual box then follow the link.


Method 1: Install Nodejs on Ubuntu 18.04 via apt command.

So on the first method, we will install the suitable version which is the distro support the best, we can also say that this will be one of the stable versions of Nodejs.

$ sudo apt update
$ sudo apt install npm
sudo apt install npm

So the above command will update the repositories and then we have to install npm.

When we install npm by default the node js package will get installed.

If still, you don’t find the node on your system, then use the apt command to install the node.

$ sudo apt install nodejs 

Now to check the node version you can use the -v option with node and npm command.

$ node -v
$ npm -v

So let’s move to our second method to install nodejs on Linux


Method 2: Install Nodejs on Ubuntu 18.04 via PPA (Personal Package Archive).

So when you have to install any specific version of nodejs and npm, then we will use the default nodejs repository. Now we will install the curl package so that we can use the curl command to download the package for node js.

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

So we have downloaded the repository for the nodejs on Ubuntu, let install the node js on Ubuntu now.

Want to install the lower version or the higher version of the Node JS just make the changes in URL.

Suppose you want to install version 10 the link will be like this “https://deb.nodesource.com/setup_10.x “.

So we have to install version 13, so URL will be “https://deb.nodesource.com/setup_13.x

Just replace that with the above command

The above command will add and update the repo, After that, it will say to run the `sudo apt-get install -y nodejs` on the Output part.

$ sudo apt-get install -y nodejs

So we have done with the installation of nodejs, let check the node version using node and npm command with the -v option.

$ node -v
$ npm -v

Method 3: Install Nodejs on Ubuntu 18.04 via NVM (Node Version Manager).

So now we will use NVM to install Nodejs on Ubuntu, with the help of this we can install as many versions for the node js as want and can be easily switched within the version itself.

We can use as many node versions in our environment, so let’s download the nvm script with the help of the curl command.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Install Node.js on Ubuntu
Install nvm on Ubuntu 18.04

So after installation of nvm on Ubuntu 18.04, we will set the source and list the node version we have using nvm.

$ source ~/.bashrc

So let’s use the above command first, and we can use the NVM command to install nodejs on Ubuntu 18.04.

$ nvm list-remote

OUTPUT:
       v14.17.5   (LTS: Fermium)
       v14.17.6   (Latest LTS: Fermium)
        v15.0.0
        v15.0.1
        v15.1.0
        v15.2.0
        v15.2.1
        v15.3.0
        v15.4.0
        v15.5.0
        v15.5.1
        v15.6.0
        v15.7.0
        v15.8.0
        v15.9.0
       v15.10.0
       v15.11.0
       v15.12.0
       v15.13.0
       v15.14.0
        v16.0.0
        v16.1.0
        v16.2.0
        v16.3.0
        v16.4.0
        v16.4.1
        v16.4.2
        v16.5.0
        v16.6.0
        v16.6.1
        v16.6.2
        v16.7.0
        v16.8.0

let’s install the stable version 14 for nodejs in Ubuntu 18.04 by using the nvm install command.

$ nvm install v14.17.6
nvm install v14.17.6
$ nvm list

So, we have to install the nodejs 14 version on Ubuntu and check the version of node js by using node and npm commands.

$ node -v
$ npm -v
nvm install v16.6.2

So now we will install 16 versions of node js and will check the version for a node then we will switch to the older version.

$ nvm install v16.6.2
Install Node.js on Ubuntu nvm list
nvm list
$ nvm list

So we can see the node version installed is 16 on Ubuntu System, want to check the node version then use node -v and npm -v.

$ nvm use v14.17.6
Install Node.js on Ubuntu nvm use to switch
nvm use v14.17.6

We have switched the version for Nodejs successfully, let’s check the version for the node.

$ node -v
$ npm -v

So in this post, we have learned How to install Nodejs on Ubuntu 18.04 with three different methods, you can use any method which suits you. Want to install Node.js on Ubuntu 20.04 follow the link. Thanks to read the post and keep supporting us.

One Reply to “Install Nodejs on Ubuntu 18.04 Linux.”

Give your valuable time