Prerequisites
This guide requires:
- A VPS running Ubuntu 24.04 LTS
- SSH access with root or sudo privileges
- Basic command line familiarity
Step 1: System updates
Begin with package list and installed software updates:
sudo apt update && sudo apt upgrade -y
Step 2: Install required packages
Add packages needed for external repository setup:
sudo apt install -y curl ca-certificates gnupg
Step 3: Configure NodeSource repository
NodeSource provides current Node.js packages beyond Ubuntu’s default versions.
Download and add the GPG key:
curl -fsSL \
https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
| sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg
Add the repository for Node.js 20 LTS:
NODE_MAJOR=20
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] \
https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" \
| sudo tee /etc/apt/sources.list.d/nodesource.list
Adjust NODE_MAJOR=20 to 18 for Node.js 18 LTS or 21 for Node.js 21.
Step 4: Install Node.js
Refresh package lists and install:
sudo apt update
sudo apt install -y nodejs
Step 5: Confirm installation
Verify Node.js and npm versions:
node --version
npm --version
Expected output shows versions like v20.x.x and 10.x.x.
Step 6: Firewall configuration
Security step often omitted from tutorials: restrict open ports.
Node.js applications typically run on specific ports (3000, 8080, etc.). Other ports should remain closed.
Using ColossusCloud’s Cloud Firewall
Configure firewall rules through the ColossusCloud control panel. Navigate to Firewall settings and establish rules allowing only necessary ports:
- Port 22 (SSH) - Consider restricting to specific trusted IP addresses or closing when not needed
- Port 80 (HTTP) - Open only if serving unencrypted traffic, otherwise redirect to HTTPS
- Port 443 (HTTPS) - Open for secure web traffic through reverse proxies like Nginx
- Application ports (e.g., 3000) - Limit to specific IP addresses if accessed directly
Set default policy to deny all other incoming traffic.
Network-level firewalls apply before traffic reaches your VPS, providing superior protection versus server-side firewall tools.
Step 7: Verification test
Create a simple test application:
mkdir ~/node-test && cd ~/node-test
Create app.js:
cat << 'EOF' > app.js
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Node.js is working!\n');
});
server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
EOF
Execute:
node app.js
With port 3000 open, access http://your-server-ip:3000 in a browser.
Press Ctrl+C to stop.
Additional resources
With Node.js installed, consider:
- Using PM2 for process management and auto-restart
- Configuring Nginx as a reverse proxy for SSL and static file serving
- Setting up Git-based deployment automation
Find the right server for Node.js applications in our VPS hosting plans.