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)
- 1SSH in and run:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs- 1Verify:
node --version
npm --version You should see v20.x.x and a recent npm.
Method 2, nvm (Recommended for Dev VPS)
- 1Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash- 1Reload your shell:
source ~/.bashrc- 1Install Node:
nvm install --lts
nvm use --ltsRun 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 appspm2 logs, tail combined logspm2 restart app, restart by namepm2 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.
Getting Started with Your Endercloud VPS
First-login checklist for a fresh Linux VPS, secure it before you build.
How to Connect via SSH (Windows & Mac)
Open a terminal session to your VPS, with password or, better, an SSH key.
How to Install a Web Server (Nginx / Apache)
Stand up Nginx or Apache on your VPS in five minutes.
Still need help?
Our team is on Discord around the clock. Real humans, real answers.