How to install Nodejs on GNU/Linux

How to install Nodejs on GNU/Linux
Source - Photo by RealToughCandy.com Nodejs 

Introduction

Today I am again with new blog. Which you might see very commonly available on internet. But explaining things in detail and easily is what I am trying to do. But I am also not saying that other blogs are not good.

So today we will going to learn :-

  1. How to install nodejs. (Install the available version from package manager)
  2. Why do we need to install it in another way? (Install the latest or specific version you want)

Let's start...

Source - https://pin.it/2YaopYn

How to install nodejs.

It is very common/easy to install most of the packages in your GNU/Linux (Now you might wonder why I am writing GNU/Linux not just Linux. Search over the internet and try to figure it out. I will definitely going to write another blog on this someday). Let's come back to topic.

In order to install nodejs package to your machine just follow these steps.

Open your terminal (This might be the shortcut CTRL + SHIFT + T) or just search for Terminal

Then type

sudo apt update

Here apt is a package manager. Which search for the required packages from repository and install it in your machine if available. This command basically check for the updates which are remaining to be completed.

Now you you can type sudo apt install nodejs

In this above command sudo means you are performing this action as a super user

Source - https://pin.it/1PeSuu8

You might be wondering if there are any other steps that are remaining. Or you will keep making us bore reading this blog.

But be happy for the fact that you just installed nodejs 🥳 into your machine 💻. But cross check for the version by typing

node -v this will tell you the currently installed version on your system.

Nodejs updated version is not available to the package manager. So you need to follow the below guideline to install the latest or the specific version you want to install in your system.

Why do we need to install it in another way?

As I just told you above the package manager (here apt is our package manager) installs the default available version from the repository to your machine.

So how do we tackle this situation?

To tackle this situation. We need to install this from some other source. Or directly through nodejs website.

So let's follow these few more steps:-

Disclaimer : I will not be responsible for any cause due to this script which you will going to execute for downloading node from nodesource. So kindly read it carefully. I am just sharing it on the basis of my good experience.

Just enter this command from the home directory for the safe practices.
To go to the home directory enter cd or cd ~
Then enter the below command but wait before you press enter key.
curl -sL https://deb.nodesource.com/setup_16.x -o /tmp/nodesource_setup.sh
In the above command replace 16.x with the specific version of nodejs you want to install into your machine.
After you replace 16 with any version of node you want you can press enter to download this specific version.

Now you can go to your /tmp folder by entering cd /tmp command. And enter sudo bash ./nodesource_setup.sh here nodesource_setup.sh is your file name.

Or you can simply execute sudo bash /tmp/nodesource_setup.sh

The PPA will be added to your configuration. You can now install the Node.js package in the same way we did in previous section:

sudo apt install nodejs

This command will install the specific version of nodejs you just downloaded.

To verify it enter node -v

Hurry you just learned how to install nodejs.

Thanks for reading hopefully you enjoyed reading this blog.