Special Offer: Save Upto 10% on Game Servers & Bot Hosting
VPS Hosting3 min read

How to Install Node.js on Your VPS

Install the latest LTS Node.js via NodeSource, the way that won't break.


Introduction

Don't install Node.js from the default apt repos, they ship ancient versions. Use NodeSource for an up-to-date LTS release, or nvm if you need to switch between versions.

Method 1, NodeSource (Recommended for Servers)

  1. 1SSH in and run:
   curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
   sudo apt install -y nodejs
  1. 1Verify:
   node --version
   npm --version

You should see v20.x.x and a recent npm.

Method 2, nvm (Recommended for Dev VPS)

  1. 1Install nvm:
   curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  1. 1Reload your shell:
   source ~/.bashrc
  1. 1Install Node:
   nvm install --lts
   nvm use --lts

Run a Node App in Production

  • Use PM2 to keep apps alive across crashes and reboots:
  sudo npm install -g pm2
  pm2 start app.js
  pm2 startup
  pm2 save
  • Pair it with Nginx as a reverse proxy on port 80/443
  • Add HTTPS with Certbot, see the web server guide

Useful PM2 Commands

  • pm2 list, show all apps
  • pm2 logs, tail combined logs
  • pm2 restart app, restart by name
  • pm2 monit, live dashboard

Warning: Don't run apps as root. Create a non-root user first.

Need More Help?

Need a hand wiring up a Node app behind Nginx? Drop your config in Discord.

Was this helpful?

Your feedback helps us write better guides.

Related Articles

More from VPS Hosting.

Still need help?

Our team is on Discord around the clock. Real humans, real answers.