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:
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

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

Step 2: Install Node.js and npm
sudo apt install nodejs

sudo apt install npm

Step 3: Verify the Installation
- Type
node -v
to check the Node.js version. - Type
npm -v
to check the npm version.

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:
- Install the NodeSource repository (Replace
18.x
with your version number)
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
- Install Node.js
sudo apt install nodejs -y
- Verify the Installation
node -v
: To check the Node.js versionnpm -v
: To check the npm version

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:

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 versionnpm -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
- Get Latest Binary
Go to: https://nodejs.org/en/download/ and download the latest one. - Unarchive It
tar -xvf node-v18.16.0-linux-x64.tar.xz
- Install to /usr/local
sudo mv node-v18.16.0-linux-x64 /usr/local/nodejs
- Update Environment Variables
echo 'export PATH=$PATH:/usr/local/nodejs/bin' >> ~/.bashrc
source ~/.bashrc
- 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.