NodeJSInstall on Linux

Install on Linux

On Linux you have several paths, and the right one depends on the role of the machine. The recommended approach for a developer workstation is a version manager (nvm/fnm); for servers, the NodeSource repositories or a pinned distro package give you reproducible, automatable installs.

Which method to choose

Method

Best for

Version freshness

nvm / fnm

Dev workstations, switching versions

Always current

NodeSource repo

Servers, Docker, CI

Current, per LTS line

Distro apt/dnf

Quick throwaway use

Often outdated

Option 1: nvm (recommended for development)

Bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# Reload your shell (or open a new terminal)
source ~/.bashrc      # or ~/.zshrc

nvm install --lts
nvm use --lts
node -v
Option 2: NodeSource (recommended for servers)

The distro's default apt package is often years behind. NodeSource publishes up-to-date packages per LTS line, ideal for servers and Docker images:

Debian / Ubuntu

Bash
# Add the NodeSource repo for the Node 20 LTS line
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

# Install
sudo apt-get install -y nodejs

node -v && npm -v

Fedora / RHEL / CentOS

Bash
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo dnf install -y nodejs
Read the script before piping to bash
`curl ... | sudo bash` runs remote code as root. It is fine for the official NodeSource URL, but as a habit, prefer downloading the script, reading it, then executing — especially on machines you do not own. This is general supply-chain hygiene; see [Dependency & Secret Security](/nodejs/dependency-security).
Option 3: Distro package manager (quick, may be old)

Bash
# Ubuntu/Debian — convenient but the version can lag badly
sudo apt update && sudo apt install -y nodejs npm
Avoid sudo with npm -g
If you installed Node system-wide, installing global packages with `sudo npm install -g` creates root-owned files in your home cache and the classic `EACCES` permission mess. A **version manager** installs Node under your home directory, eliminating `sudo` entirely — the single biggest reason to prefer nvm/fnm on a workstation.
Docker — a fourth common path

On servers you often do not install Node on the host at all — you base a container on an official image. -slim trims size; -alpine is smallest but uses musl libc, which can break native add-ons:

Dockerfile

Text
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
CMD ["node", "server.js"]
Verify the architecture
ARM servers are common now
On ARM hosts (AWS Graviton, Raspberry Pi, Ampere) make sure you have the arm64 build — NodeSource and nvm pick it automatically. Confirm with `node -p "process.arch"`, which should print `arm64` or `x64` as expected. A mismatch shows up as native modules failing to load.
Verify

Bash
node -e "console.log('Hello from Linux + Node')"
Hello from Linux + Node
Next
Pin the project's version with [nvm](/nodejs/nvm) and understand [LTS vs Current Releases](/nodejs/nodejs-versions).