Installing Node.js on a Linux-based operating system can vary slightly depending on your distribution. This guide will walk you through various methods to install Node.js and npm (Node Package Manager) on Linux, whether using Ubuntu, Debian, or other distributions.
Prerequisites1. Use Package ManagerLooking to host your Node.js applications? Hostinger’s affordable VPS hosting offers an optimized environment for seamless development and deployment. With pre-configured Node.js templates on Ubuntu 22.04 and OpenLiteSpeed server support, you get a performance boost right out of the box. For beginners, Hostinger’s CloudPanel template makes Node.js app creation simple. Plus, with scalable plans, you have full control to customize your server setup, making it perfect for developers at any stage.
For most Linux distributions, the easiest way to install Node.js is through the default package manager. Here’s how to do it for common distributions:
Steps to Install Node.js on Ubuntu/Debian Step 1: Update your systemBefore installing Node.js, make sure your package list is up to date.
sudo apt updatesudo apt updateStep 2: Upgrade the system
Once updates are installed you need to upgrade your system and to do this enter the below command.
sudo apt upgradesudo apt upgradeStep 3: Install Node.js
Ubuntu and Debian come with the apt
package manager, which can be used to install Node.js. You can install Node.js directly from the official Ubuntu repositories.
sudo apt install nodejsStep 4: Install npm
npm is the package manager that comes bundled with Node.js. If it is not installed automatically, you can install it separately.
sudp apt install npmsudo apt install npmStep 5: Verify the Installation
To confirm that Node.js and npm are installed correctly, you can check their versions using:
node -v
and press Enter to check the Node.js version.npm -v
and press Enter to check the npm version.sudo yum updateStep 2: Install Node.js
You can install Node.js by adding the NodeSource repository:
curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash -Step 3: Verify the Installation
sudo yum install -y nodejs
Open Terminal to check the installed versions by running these commands:
NVM is a popular way to install and manage multiple versions of Node.js. It's ideal if you need to use different versions of Node.js for various projects or if you want to easily upgrade or downgrade Node.js versions.
Step 1: Install and Activate NVMFirst, download and install NVM using the following script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bashnvm
Once installed, you need to add NVM to your shell configuration. You can do this by running the following command:
source ~/.bashrcbash Step 2: Install Node.js Using NVM
To install the latest LTS (Long Term Support) version of Node.js, run:
nvm install --lts
Step 3: Verify the InstallationSwitch Node.js Versions
If you need to switch between multiple versions, you can list installed versions using: nvm ls
To switch to a specific version you can use: nvm use 22
You may now verify the nodejs installation using the following command:
node -v
and press Enter to check the Node.js version.npm -v
and press Enter to check the npm version.Note: Both commands should return version numbers, confirming successful installation.
3. Install Node.js from NodeSourceNodeSource provides an up-to-date repository that ensures you get the latest version of Node.js.
Step 1: Add NodeSource repositoryNote: To install NVM on your Ubuntu machine, visit the project’s GitHub page. Copy the
curl
command from the README file that displays on the main page to get the most recent version of the installation script.
NodeSource maintains separate repositories for each version of Node.js. To install the latest version of Node.js
Before running your actual curl command if you are not a sudo user or root user run the below command:
sudo su
curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -Step 2: Install Node.js
After adding the repository, install Node.js using apt
(for Debian-based systems):
sudo apt install -y nodejsStep 3: Verify Installation by node -v and npm -v
Use the following command to verify the installations:
node -v
npm -v4. Using Snap
Snap is another method for installing Node.js on Linux, especially for those who prefer installing software in a containerized form.
Step 1: Install Node.js with SnapOn Ubuntu and other distributions that support Snap, you can install Node.js directly:
sudo snap install node --classicStep 2: Verify Installation
After installation, check the Node.js version:
node -vverify the installations Conclusion
Installing Node.js on Linux is a relatively simple process, but it can vary depending on your distribution and preferred installation method. Using package managers like apt or yum is the easiest method for most users, while NVM provides greater flexibility for managing multiple Node.js versions. With these installation methods, you can easily get Node.js up and running on your Linux machine.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4