What you will achieve
Node.js LTS on Linux via NodeSource or distro packages — avoiding ancient Debian stock versions when you need current LTS.
1) NodeSource (Ubuntu/Debian)
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
2) Fedora module stream
sudo dnf module list nodejs
sudo dnf module install nodejs:22/common
3) nvm (per-user, multiple versions)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
nvm install --lts
nvm use --lts
4) Verify npm global paths
npm config get prefix
Avoid sudo npm -g; use nvm or a user prefix.
Verify
node -v
npm -v
5) Corepack for yarn/pnpm
sudo corepack enable
corepack prepare pnpm@latest --activate
6) Build tools for native modules
sudo apt install build-essential python3
node-gyp needs compiler toolchain for bcrypt, sharp, etc.
7) systemd service for Node app
[Service]
ExecStart=/usr/bin/node /opt/app/server.js
WorkingDirectory=/opt/app
User=www-data
Restart=on-failure
Environment=NODE_ENV=production
Avoid mixing install methods
Pick apt, NodeSource, or nvm — not all three. Multiple node binaries in PATH cause "works in shell, fails in cron" bugs.
8) npm audit in CI
npm audit --production
OS node package version and project package.json engines field should align — document both in README.
Prerequisites
curl or package manager access. Know required Node major version from project .nvmrc or engines field. Build tools if native modules. Non-root npm strategy decided upfront.
fnm alternative
curl -fsSL https://fnm.vercel.app/install | bash
fnm install --lts
Rust-based version manager — fast alternative to nvm on developer workstations.
global npm prefix
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'Add to PATH in .profile — global CLIs without sudo.
distro vs upstream trade-off
Debian stock node often ancient — fine for system tools depending on it; app development uses NodeSource or nvm. Mixing causes /usr/bin/node v12 and nvm v22 — PATH order in systemd unit Environment=PATH must pin correct binary.
openssl legacy providers
Old webpack projects on Node 18+ may need openssl legacy provider flag — document in package.json scripts not system-wide node change affecting other apps.
yarn via corepack
corepack enable
corepack prepare yarn@stable --activateModern monorepos expect yarn berry — corepack ships with Node 16+ without separate yarn apt package.
deb nodesource removal
If switching from NodeSource to nvm remove /etc/apt/sources.list.d/nodesource.list before apt update — stale repo causes confusing apt errors on unrelated upgrade.
engines field enforcement
package.json engines.node — CI fails build on wrong node version — document LTS choice in README matching install method from this guide.