How to Install Node.js on VPS (Ubuntu 24.04 & Debian 12 Guide)
How to Install Node.js on VPS (Ubuntu 24.04 and Debian 12)
If you plan to build web applications, APIs, or real-time projects on your server, you’ll need Node.js installed properly. In this tutorial, you’ll learn how to install Node.js on VPS step by step. We’ll cover the process for both Ubuntu 24.04 and Debian 12, using different methods: default repositories, NodeSource, and NVM. Whether you’re deploying on a production Linux VPS or experimenting as a developer, this guide will help you get Node.js up and running smoothly.
1. Update Your VPS
sudo apt update && sudo apt upgrade -y
2. Installing Node.js from Official Repositories
sudo apt install -y nodejs npm
node -v
npm -v
node -v
npm -v
3. Installing Node.js via NodeSource (Recommended for Latest Versions)
sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
node -v
npm -v
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
node -v
npm -v
4. Installing Node.js via NVM (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts
node -v
source ~/.bashrc
nvm install --lts
node -v
5. Verifying Node.js Installation
node -e "console.log('Node.js is installed successfully!')"
6. Best Practices After Installation
sudo apt install -y build-essential
Use PM2 or systemd to keep apps running.
7. Are the Installation Steps Different on Ubuntu and Debian?
Almost no difference. Both use apt. Ubuntu may ship slightly newer Node.js packages; Debian sometimes requires npm installed separately.
8. Example: Running Your First Node.js App on VPS
// app.js
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World from Node.js on VPS!\n');
});
server.listen(3000, () => {
console.log('Server running at http://0.0.0.0:3000/');
});
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World from Node.js on VPS!\n');
});
server.listen(3000, () => {
console.log('Server running at http://0.0.0.0:3000/');
});
Run with:
node app.js
Visit:
http://your_server_ip:3000
9. Keep Your App Running in the Background
sudo npm install -g pm2
pm2 start app.js
pm2 start app.js
10. Quick Install: Node.js LTS (One-Liner)
For those who want the fastest setup of the latest Node.js LTS on Ubuntu 24.04 or Debian 12:
sudo apt update && sudo apt install -y curl \
&& curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - \
&& sudo apt install -y nodejs build-essential \
&& node -v && npm -v
&& curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - \
&& sudo apt install -y nodejs build-essential \
&& node -v && npm -v
This one-liner updates your system, adds NodeSource, installs Node.js + npm + build tools, and confirms the versions.
Conclusion
By now, you’ve seen multiple ways to install Node.js on VPS running Ubuntu 24.04 or Debian 12. With Node.js installed on your VPS, you’re ready to start deploying scalable apps, testing new projects, or running production-ready environments.
FAQ — Installing Node.js (Ubuntu 24.04 & Debian 12)
You ask, and we answer! Here are the most frequently asked questions!
-
Which Node.js version should I use on my VPS?
- Use the latest LTS (currently Node.js 20.x).
-
How do I keep Node.js updated?
- Via apt upgrade, NodeSource, or NVM
-
Can I install multiple Node.js versions?
- Yes, with NVM.
-
Do I need npm?
- Yes. Install separately if missing: sudo apt install -y npm
-
Can I run multiple Node.js apps?
- Yes, assign different ports and use PM2 or Nginx.
-
Is installation the same on Ubuntu and Debian?
- Yes, steps are nearly identical.