OKAll services are operational
InfrawireInfrawire LogoDocumentation

Install Node.js and npm on a Linux VPS

This guide explains how to install Node.js (JavaScript runtime) and npm (package manager) on an Ubuntu or Debian VPS to run web apps (Express, NestJS, build tools, etc.).

Prerequisites

  • Linux VPS with sudo or root SSH access
  • Ubuntu 20.04+ or Debian 11+ (64-bit)
  • Working SSH connection

Recommendation

For frequent builds (npm install, compilations), prefer a VPS with fast storage such as our NVMe VPS.

1. Update the system

Bash
sudo apt update && sudo apt upgrade -y

2. Install prerequisites

Bash
sudo apt install -y ca-certificates curl gnupg

3. Add the NodeSource key and repository (example: Node.js 22.x LTS)

Replace 22.x with your desired LTS branch using the NodeSource distributions documentation.

Bash
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -

4. Install Node.js

Bash
sudo apt install -y nodejs

5. Verify

Bash
node -v npm -v

Quick alternative: distro packages

Bash
sudo apt install -y nodejs npm

Versions may be older than with NodeSource. For production, prefer NodeSource or a version manager (nvm).

Update npm (optional)

Bash
sudo npm install -g npm@latest

Best practices

  • Avoid running project npm commands as root: use a dedicated user or sudo -u myuser.
  • For production, consider PM2 or a systemd unit to restart the app on boot.
  • Open only required ports (firewall, Nginx reverse proxy in front of the app).

Troubleshooting

  • Permission denied on global npm install -g: configure a user-level global directory or use nvm.
  • Command not found after install: reconnect SSH or open a new shell.

Next steps: harden SSH and Nginx + Certbot for HTTPS.