Installing node.js on Linux [Step by Step Guide]

Introduction

In this tutorial, we will learn about installing node.js on Linux using step by step guide. Nodejs is an open source tool which act as a runtime environment for JavaScript. We will learn about its definition and usage in the next section. We will also look at how node.js package is installed on different distribution of Linux using package manager. Let’s get started.

 

Installing node.js on Linux [Step by Step Guide]

Node.js Overview

Node.js is an open source server side JavaScript runtime environment that allows you to execute JavaScript code outside of a web browser. It is versatile and powerful runtime environment for JavaScript that has found applications in a wide range of use cases, including web development, real-time applications, microservices, IoT and more. Its non-blocking, event-driven architecture and vast ecosystem of packages make it a popular choice for developers and organizations looking to build efficient and scalable server-side applications.

 

Installing node.js on Linux [Step by Step Guide]

Also read: Install Maven on Linux [Step by Step Configuration Guide]

Prerequisite

  • User having sudo privilege/root user privilege required
  • Linux operating system installed
  • Basic understanding of Linux CLI commands.

 

Install on Ubuntu

To install the node.js on Ubuntu Follow below steps in order. First of all, update and upgrade the apt-get repository by executing below commands. This will update all the packages in the repository to it’s latest version and remove the obsolete packages from the repository.

[root@linuxnasa]# apt-get update
[root@linuxnasa]# apt-get upgrade

 

Next, install the node.js package using below command.

[root@linuxnasa]# apt-get install -y nodejs

 

Next, after installing the node.js package, verify if it is installed successfully in your machine by executing below command.

[root@linuxnasa]# node -v/node --version

 

Next, it is recommended to install npm package manager with node.js. To install, use below command.

[root@linuxnasa]# apt-get install -y npm

 

Next, Verify if npm is installed successfully in your machine using below command.

[root@linuxnasa]# npm -v/npm --version

 

NOTE:

You can also install node.js by downloading node.js archive. Please follow the guide How to Install the latest version of Node.js on Ubuntu/Debian to install from node.js archive.

 

Install on RHEL/CentOS 7

In RHEL/CentOS 7 distribution, yum package manager is used for installing the packages. Let us update and upgrade the yum repository using below command.

[root@linuxnasa]# yum update
[root@linuxnasa]# yum upgrade

 

Next, install the node.js package using below command.

[root@linuxnasa]# yum install -y nodejs

 

Next, verify if node.js package is installed successfully by executing below command.

[root@linuxnasa]# node -v/node --version

 

Next, install npm package using below command.

[root@linuxnasa]# yum install -y npm

 

Next, verify if npm package is installed successfully in your machine using below command.

[root@linuxnasa]# npm -v

 

Install on CentOS 8/Rocky Linux

In CentOS 8/ Rocky Linux distribution, dnf package manager is used to install the packages. We will first update and upgrade dnf repository as we did in previous steps  using below command.

[root@linuxnasa]# dnf update
[root@linuxnasa]# dnf upgrade

 

Next, install nodejs package using dnf package manager by executing below command.

[root@linuxnasa]# dnf module install -y nodejs

 

Next, verify if nodejs is installed in your machine using below command.

[root@linuxnasa]# node -v

 

Next, install npm package using below command.

[root@linuxnasa]# dnf install -y npm

 

Next, verify if npm is installed successfully on your machine using below command.

[root@linuxnasa]# npm -v

 

Summary

We have successfully installed nodejs package on different distribution of Linux. You can also install nodejs on different operating systems like Windows and macOS. You can follow the guide from nodejs.org to install on any other operating system.

Leave a Comment