Install Node.js on Linux
Introduction
This chapter teaches you how to install Node.js on Linux in a clean, production-friendly way. You will use distribution package managers where appropriate, verify node and npm, and learn when nvm is worth adding. Many servers and CI pipelines run Linux—getting this setup right transfers directly to real jobs.
Prerequisites
- A Linux machine (Ubuntu, Debian, Fedora, RHEL-family, or similar)
- Basic terminal knowledge and
sudofor system packages - Internet access to package repositories or nodejs.org
- Completed What Is JavaScript
Choose the Right Installation Strategy
Linux offers several installation paths:
| Method | Best for |
|---|---|
Distro packages (apt, dnf) | Quick setup, OS-managed updates |
| Official NodeSource / nodejs.org | Newer LTS when distro packages lag |
| nvm | Multiple Node versions on one machine |
Recommended for learners:
- Start with distro packages on Ubuntu/Debian or Fedora if versions are recent enough
- Use nvm when you need flexible version switching per project
Warning
Avoid mixing several Node installations on one PATH without understanding precedence. Run which -a node if versions look wrong.
Install Node.js on Debian and Ubuntu
# Update package index
sudo apt update
# Install Node.js and npm (package names may vary slightly by release)
sudo apt install -y nodejs npm
# Verify versions
node --version
npm --versionIf apt provides an older Node than your project requires, use nvm (below) or follow NodeSource setup guides for a current LTS.
Tip
Best Practice
On servers, run apt update before installing Node.js to reduce SSL and dependency issues.
Install Node.js on Fedora / RHEL-like Systems
# Install Node.js and npm
sudo dnf install -y nodejs npm
# Verify versions
node --version
npm --versionInstall Node.js with nvm (Optional, Flexible Versions)
nvm (Node Version Manager) installs Node under your home directory and lets you switch versions per shell session.
# Install nvm (check https://github.com/nvm-sh/nvm for the latest install script)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# Load nvm in the current shell (or open a new terminal)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install and use the latest LTS
nvm install --lts
nvm use --lts
# Verify
node --version
npm --versionAdd the NVM_DIR lines to your ~/.bashrc or ~/.zshrc so nvm loads automatically.
Verify and Troubleshoot
# Show which node binary runs
which node
# List all node binaries on PATH (if multiple)
which -a node| Problem | Likely cause | Fix |
|---|---|---|
node: command not found | Not installed or PATH not loaded | Reinstall; source shell rc file for nvm |
| Version too old for a tutorial | Distro package lag | Use nvm or official LTS packages |
npm missing | Split packages on minimal images | Install npm package alongside nodejs |
FAQ
Should I use system Node.js for all development on Linux?
For learning and small projects, a user-level nvm install often causes fewer conflicts with OS tools than overwriting system Node. On dedicated dev machines, either approach works if you understand PATH.
When should I use nvm on Linux?
Use nvm when you maintain projects on different Node LTS lines (for example Node 20 vs 22) on the same laptop or VM.
Why does nodejs exist on some distros instead of node?
Debian historically packaged the binary as nodejs. Many setups provide a node symlink. If only nodejs exists, check your distro docs or install via nvm for a standard node command.
Can I run JavaScript in the browser without Node.js on Linux?
Yes—browser engines are separate. This course still installs Node.js for CLI scripts, local tooling, and backend chapters.
How do I upgrade Node.js safely?
With apt/dnf, use your distro upgrade path. With nvm, run nvm install --lts and nvm alias default <version>. Re-test projects after major version bumps.