Updated: 18 November 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9 with Node.js 24 LTS
Node.js runs JavaScript on the server. Install the current LTS version from the NodeSource repository.
The operating system versions in the original guide (CentOS 7, Ubuntu 16.04/18.04, Debian 8/9) are no longer supported, so this guide uses Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9.
Install Node.js (current LTS)
Use the NodeSource packages for the current Long-Term-Support release (24.x at the time of writing; check nodejs.org):
curl -fsSL https://deb.nodesource.com/setup_24.x | bash - # Ubuntu / Debian apt install nodejs curl -fsSL https://rpm.nodesource.com/setup_24.x | bash - # AlmaLinux / Rocky dnf install nodejs
Check with node -v and npm -v.
Tip: For development machines, or several Node versions side by side, use nvm instead: install it from its GitHub page, then nvm install --lts.
Run an app with PM2
npm install -g pm2 pm2 start app.js --name myapp pm2 startup && pm2 save
PM2 restarts the app if it crashes and after reboots. Put Nginx in front of it for HTTPS.
Update or switch the Node.js version
- Updates within the same major version arrive with
apt upgradeordnf upgrade. - To move to a newer LTS, run the NodeSource setup script for that version (for example
setup_26.xonce 26 is LTS) and installnodejsagain. Test your app first: native modules may neednpm rebuild. - Remove Node.js with
apt remove nodejsordnf remove nodejs.
Common problems
- EACCES errors with npm install -g: do not use
sudo npmfor project packages. Install them per project, or set a user prefix:npm config set prefix ~/.npm-globaland add~/.npm-global/binto your PATH. - node: command not found after installing nvm: open a new shell or run
source ~/.bashrc. - App stops when you close SSH: run it with PM2 or a systemd service instead of in the foreground.