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 | Quick throwaway use | Often outdated |
Option 1: nvm (recommended for development)
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
# 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
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash - sudo dnf install -y nodejs
Option 3: Distro package manager (quick, may be old)
# Ubuntu/Debian — convenient but the version can lag badly sudo apt update && sudo apt install -y nodejs npm
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
FROM node:20-slim WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . CMD ["node", "server.js"]
Verify the architecture
Verify
node -e "console.log('Hello from Linux + Node')"Hello from Linux + Node