Installation of NodeJS and NPM on Linux.

installation of nodejs

Introduction

This tutorial will cover “Installation of NodeJS and NPM in Linux”. So we will install NodeJS on both the distributors(Ubuntu and CentOS).

Using the curl command, we will install the NodeJS and NPM via Source code. Node JS is an open-source and cross-platform application. It can run on various platforms like Linux, Windows, and Mac Operating systems.

To execute the JS(JavaScript) Code it uses the V8 engine with the JS runtime environment. Node js has the file extension .js as like java has .java and PHP has .php.

NodeJS modules use Node Package Manager(NPM), which is the package registry. Want to learn more about NodeJS then refer to the link.

So we will cover 3 topics for the Installation of NodeJS and NPM.

  1. How to Install NodeJS and NPM in Ubuntu.
  2. How to Install NodeJS and NPM in CentOS.
  3. Quick View to Install NodeJS and NPM in CentOS and Ubuntu.

Prerequisite

  1. We want Ubuntu and CentOS distributors with sudo privileges.
  2. Want curl command to download the package for Node JS.

Installation of NodeJS and NPM in Ubuntu.

So we will install the curl command in Ubuntu using the apt-get command.

$ sudo apt-get install -y curl 

Once you install the curl command then download the source package for NodeJS.

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

While writing the post the Long Term Support for the NodeJS is 12.x and the current stable version is 13.x.

Suppose you want to install the lower or higher version of the Node JS, then make the changes in the above URL. Let’s understand with 2 different examples.

  1. If you want to install version 10 then the URL will be “https://deb.nodesource.com/setup_10.x “.
  2. If you want to install version 13 then URL will be “https://deb.nodesource.com/setup_13.x “.

As per the need, we can change the version while downloading the source code.

So the above command will add and update the repo then use the below command to install NodeJS and NPM.

$ sudo apt-get install -y nodejs

To verify the installed version you can use “node -v” and “npm -v”.

$ node -v
$ npm -v

Installation of NodeJS and NPM in CentOS.

So we will install the curl command in the CentOS distributor using the “yum command”.

$ sudo yum install -y curl

Once you install the curl command then download the source package for NodeJS.

$ sudo curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -

Suppose you want to install the lower or higher version of the Node JS, then make the changes in the above URL.

So the above command will add and update the repo and it will prompt to execute the below command.

$ sudo yum install -y nodejs

Once the package gets installed then use “node -v” and “npm -v” to verify.

$ node -v
$ npm -v

Now there is a repository named nodesource on GitHub. On the above commands we have used “|sudo bash -” after the URL because they are using a shell script to install the package.


Quick View to Install NodeJS and NPM in CentOS and Ubuntu.

So this is the Quick view section where you can get the steps to install NodeJS and NPM in Linux distributors.

Installation of NodeJS and NPM on Ubuntu
$sudo apt-get install curl

So if you want to install the lower version or the higher version of the Node JS just makes the changes in URL.

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

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

So just replace that with the below command.

$curl -sL https://deb.nodesource.com/setup_12.x |sudo -E bash -
$sudo apt-get install -y nodejs
$node -v 
$npm -v 
Installation of NodeJS and NPM CentOS.
#sudo yum install curl

So if you want to install the lower version or the higher version of the Node JS just makes the changes in URL.

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

If we have to install version 13 so URL will be “https://rpm.nodesource.com/setup_13.x “.

Just replace that with the below command

$sudo curl -sL https://rpm.nodesource.com/setup_12.x |sudo bash -
$sudo yum install -y nodejs
$node -v 
$npm -v 

Conclusion

So in this article, we have discussed the steps to Install Nodejs and NPM(Node Package Manager) in Linux. How you can install any version of Node and NPM, as per the project need. Install Node and NPM using NVM. If you find any issues or feedback let us know in the comment section.


One Reply to “Installation of NodeJS and NPM on Linux.”

Give your valuable time