How to Install Node.js on Linux Using NVM, Packages, and NodeSource
This guide walks you through installing Node.js on various Linux distributions by using NVM for version management, native package managers for stable releases, and the NodeSource repository for the latest versions, complete with commands, verification steps, and troubleshooting tips.
Introduction
Node.js is an open‑source, cross‑platform JavaScript runtime built on Chrome's V8 engine, used to create scalable network applications. It includes the npm command‑line utility for managing packages. This tutorial explains three ways to install Node.js on popular Linux distributions.
1. Install Node.js with NVM (Recommended)
NVM (Node Version Manager) is a bash script that lets you install, uninstall, and switch between multiple Node.js versions without permission issues.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bashor
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bashThe script clones the NVM repository into ~/.nvm and adds source lines to your shell profile ( ~/.bashrc, ~/.zshrc, etc.). After restarting the terminal, verify the installation: command -v nvm Output should be nvm.
List available Node.js versions: nvm ls-remote Install the latest version: nvm install node Install a specific version (e.g., v12.20.2): nvm install v12.20.2 View installed versions: nvm list Switch to a version: nvm use node Set a default version: nvm alias default v12.20.2 Uninstall a version (after deactivating if it is active):
nvm uninstall v12.20.22. Install Node.js via Distribution Package Managers (Stable but Older)
Most Linux distributions provide Node.js in their default repositories. Use the following commands for each distro:
Arch Linux (and derivatives): sudo pacman -S nodejs npm Debian/Ubuntu/Mint: sudo apt-get install nodejs npm RHEL/CentOS (enable EPEL first): sudo yum install epel-release then sudo yum install nodejs npm Fedora: sudo dnf install nodejs npm If the node binary is missing, create a symlink:
sudo ln -s /usr/bin/nodejs /usr/bin/node3. Install Node.js from NodeSource (Latest Versions)
NodeSource provides up‑to‑date packages for various Node.js releases. Add the appropriate repository and install:
Node.js 15.x (Ubuntu):
curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bashNode.js 14.x:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -Node.js 12.x:
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -Node.js 10.x:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -Node.js 8.x:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -After adding the repository, install Node.js: sudo apt-get install nodejs npm For RHEL/CentOS, use the RPM setup scripts (e.g., curl -sL https://rpm.nodesource.com/setup_15.x | sudo bash -) and then sudo yum install nodejs npm. Fedora follows the same steps with dnf.
Optional: Install Build Tools for Native npm Modules
To compile native addons, install development tools:
Debian/Ubuntu: sudo apt-get install -y build-essential RHEL/CentOS: sudo yum groupinstall 'Development Tools' Fedora:
sudo dnf groupinstall 'Development Tools'Resources
Node.js official website
NVM GitHub repository
NodeSource website
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
