Updated: 28 September 2026 · Applies to: Ubuntu 24.04 LTS with Node.js 24 LTS
Ubuntu 18.04 is no longer supported; this guide uses Ubuntu 24.04 LTS.
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.
Your first app
mkdir ~/hello && cd ~/hello
npm init -y
cat > app.js <<'EOF'
const http = require('http');
http.createServer((req, res) => res.end('Hello from Node.js\n')).listen(3000, '127.0.0.1');
EOF
node app.js
Test from the server with curl http://127.0.0.1:3000. Use PM2 to keep it running and Nginx as a reverse proxy for public access.
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.