Installing Node.js on Linux: A Comprehensive Guide

Installing Node.js on Linux

Table of Contents

Get up to 50% off now

Become a partner with CyberPanel and gain access to an incredible offer of up to 50% off on CyberPanel add-ons. Plus, as a partner, you’ll also benefit from comprehensive marketing support and a whole lot more. Join us on this journey today!

Node.js is a JavaScript runtime environment that an application developer uses to create web applications that are scalable. Node.js is popularly used in backend development, real-time applications, and full-stack JavaScript frameworks like React, Angular, and Vue.js. Since the most prevalent operating system upon which to develop as well as deploy software is Linux, being aware of how to install Node.js with efficiency is important.

This tutorial describes multiple methods of installing Node.js on Linux distributions, i.e., Amazon Linux, and Kali Linux. Additionally, it also mentions how to handle multiple versions of Node.js via Node Version Manager (NVM) and source installation.

1. Verifying if Node.js is already installed

Before even installing Node.js on Linux, check if it is already installed in your system.

Run the following command to check the version of Node.js installed:

node -v

or

node --version

Check if npm (Node Package Manager) is installed:

Tech Delivered to Your Inbox!

Get exclusive access to all things tech-savvy, and be the first to receive 

the latest updates directly in your inbox.

npm -v

If Node.js is not installed, follow one of the below options.

2. Installing Node.js with Package Managers

Node.js is available in most Linux distributions within their respective default repositories. Installing Node.js on Linux varies with the package manager of the distribution.

Install Node.js on Debian-Based Systems (Ubuntu, Debian, Linux Mint)

Debian systems utilize the Advanced Package Tool (APT) to install packages.

Step 1: Update the System

sudo apt update

Installing Node.js on Linux

Once updates are installed you need to upgrade your system and to do this enter the below command.

sudo apt upgrade

Node.js on Linux

Step 2: Install Node.js and npm

sudo apt install nodejs
Node.js on Linux
sudo apt install npm
Node.js on Linux

Step 3: Verify the Installation

  • Type node -v to check the Node.js version.
  • Type npm -v to check the npm version.
Node.js on Linux

This should have the default distribution repository version that may not be the newer one.

Installing the Newest Version from NodeSource

To get the latest version of Node.js, use the NodeSource repository:

  1. Install the NodeSource repository (Replace 18.x with your version number)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
  1. Install Node.js
sudo apt install nodejs -y
  1. Verify the Installation
  • node -v: To check the Node.js version
  • npm -v: To check the npm version
Node.js on Linux

3. Installing Node.js using NVM (Node Version Manager)

NVM is an excellent utility to manage multiple Node.js versions.

Step 1: Installing NVM

curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

Reload the shell profile:

Enhance Your CyerPanel Experience Today!
Discover a world of enhanced features and show your support for our ongoing development with CyberPanel add-ons. Elevate your experience today!

source ~/.bashrc

or

source ~/.zshrc

Step 2: Installing Node.js using NVM

nvm install 18

Install a default Node.js version:

nvm use 18
nvm alias default 18

Check installation:

  • node -v: To check the Node.js version
  • npm -v: To check the npm version

4. Installing Node.js on Specific Linux Distributions

4.1 Installing Node.js on Amazon Linux

Amazon Linux is optimized for AWS environments where Node.js should be installed most efficiently. The Amazon Extras repository should be used.

Step 1: Enable the Node.js Extras Repository

sudo amazon-linux-extras enable nodejs18

Step 2: Install Node.js

sudo dnf install -y nodejs

Step 3: Check Installation

node -v
npm -v

4.2 Installing Node.js on Kali Linux

Kali Linux is Debian-based, and the commands are identical to Ubuntu.

Step 1: Update the Package List

sudo apt update && sudo apt upgrade -y

Step 2: Install Node.js and npm

sudo apt install nodejs npm -y

Step 3: Verify Installation

node -v
npm -v

Installing the latest one, use NodeSource:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs

5. Install Node.js with Binary Files

  1. Get Latest Binary
    Go to: https://nodejs.org/en/download/ and download the latest one.
  2. Unarchive It
tar -xvf node-v18.16.0-linux-x64.tar.xz
  1. Install to /usr/local
sudo mv node-v18.16.0-linux-x64 /usr/local/nodejs
  1. Update Environment Variables
echo 'export PATH=$PATH:/usr/local/nodejs/bin' >> ~/.bashrc
source ~/.bashrc
  1. Check Installation
node -v
npm -v

6. Installing Node.js from Source Code

For those who enjoy compiling Node.js from source code.

Step 1: Install Build Dependencies

sudo apt install build-essential python3

Step 2: Clone the Repository

git clone https://github.com/nodejs/node.git
cd node

Step 3: Compile and Install

./configure
make -j$(nproc)
sudo make install

Step 4: Verify Installation

node -v
npm -v

Conclusion

Installing Node.js on Linux is simple, with a number of ways to install it. The simplest ways are via package managers, but NVM provides flexibility when controlling versions. AWS developers must use Amazon Linux Extras. Developers who can follow Debian-based system instructions can apply them. Developers who desire total control can install Node.js from source or binaries.

FAQs

1. What is Node.js, and why do I need it for Linux?

Node.js is a JavaScript runtime that lets you run JavaScript outside of the browser, mainly for server-side programming. It is used quite extensively for creating web applications, APIs, real-time apps, and microservices. installing Node.js on Linux enables developers to run and deploy JavaScript applications within a server environment efficiently.

2. What are the various ways to install Node.js on Linux?

You can install Node.js on Linux using the following methods:

Using a package manager (APT for Ubuntu/Debian, DNF/YUM for RHEL-based distros, Pacman for Arch)
Using Node Version Manager (NVM) – Best for managing multiple versions
Installing from NodeSource – Provides the latest version of Node.js
Downloading precompiled binaries from the official Node.js website
Building from source – Suitable for advanced users who need a custom build

3. Can I install Node.js without root/sudo access?

Yes, by using NVM, you can install and manage Node.js in your user directory without requiring root access.

Shumail
Shumail is a skilled content writer specializing in web content and social media management, she simplifies complex ideas to engage diverse audiences. She specializes in article writing, copywriting, and guest posting. With a creative and results-driven approach, she brings fresh perspectives and attention to detail to every project, crafting impactful content strategies that drive success.
Unlock Benefits

Become a Community Member

SIMPLIFY SETUP, MAXIMIZE EFFICIENCY!
Setting up CyberPanel is a breeze. We’ll handle the installation so you can concentrate on your website. Start now for a secure, stable, and blazing-fast performance!