How to Install Node.js on a Linux Server

nodejs logo

Introductions:

Node.js is a powerful, open-source JavaScript runtime environment that allows developers to build fast, scalable, and server-side applications. It’s widely used for developing web servers, APIs, and full-stack JavaScript applications.

In this guide, we’ll walk you through step-by-step instructions to install Node.js on your Linux server (Ubuntu, Debian, AlmaLinux, CentOS, or Rocky Linux) using different methods.

Prerequisites

Before starting, make sure:

  • You have SSH access to your Linux server.
  • You are logged in as a root user or a user with sudo privileges.
  • The system is up-to-date.

Update your server package list:

sudo apt update && sudo apt upgrade -y     # For Ubuntu/Debian
sudo dnf update -y                         # For AlmaLinux/CentOS/Rocky

Step 1: Check if Node.js Is Already Installed

First, verify if Node.js is already installed on your server:

node -v

If you see a version number (e.g., v20.11.0), Node.js is already installed.
If not, continue with the installation steps below.

Step 2: Install Node.js Using the Package Manager

Install from the Default Repository

Most Linux distributions include Node.js in their repositories, but the version may be outdated.

On Ubuntu/Debian:

sudo apt install nodejs -y
sudo apt install npm -y

On CentOS/RHEL/AlmaLinux:

sudo dnf module install nodejs:20 -y

After installation, verify:

node -v
npm -v

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top