Install Node.js on Ubuntu 24.04 LTS | VPS Tutorial | ServerPoint Skip to main content
Linux

How to install Node.js on Ubuntu 24.04 LTS

By ServerPoint's Team January 15, 2026

Before you start

This guide assumes you have:

Step 1: Update your system

Always start by updating your package lists and installed packages:

sudo apt update && sudo apt upgrade -y

Step 2: Install dependencies

Install the required packages for adding external repositories:

sudo apt install -y curl ca-certificates gnupg

Step 3: Add the NodeSource repository

NodeSource provides official Node.js packages that are more up-to-date than Ubuntu’s default repositories.

First, download and add the NodeSource GPG key:

curl -fsSL \
  https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
  | sudo gpg --dearmor -o /usr/share/keyrings/nodesource.gpg

Then add the NodeSource repository. This example uses 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

Want a different version? Change NODE_MAJOR=20 to NODE_MAJOR=18 for Node.js 18 LTS, or NODE_MAJOR=21 for Node.js 21.

Step 4: Install Node.js

Update your package list to include the new repository, then install Node.js:

sudo apt update
sudo apt install -y nodejs

Step 5: Verify the installation

Check that Node.js and npm are installed correctly:

node --version
npm --version

You should see version numbers like v20.x.x and 10.x.x.

Step 6: Secure your VPS with the firewall

Here’s an important security step that many tutorials skip: close all unnecessary ports.

Your Node.js application probably runs on a specific port (like 3000 or 8080). There’s no reason to leave other ports open to the internet.

Use ServerPoint’s Cloud Firewall via ServerPoint’s Client Portal

In your ServerPoint’s Client Portal, you can configure firewall rules for your VPS. Go to the Firewall section and set up rules that allow only the ports you need:

  • Port 22 (SSH) - Block this in the Global firewall setting. Only open it when you need access, or restrict it to specific IP addresses you trust.
  • Port 80 (HTTP) - Only open this if you intend to serve non-secure traffic. For most modern applications, you should redirect HTTP to HTTPS instead.
  • Port 443 (HTTPS) - Open this if serving secure web traffic through a reverse proxy like Nginx.
  • Your application port (e.g., 3000) - If accessed directly, limit this to specific IP addresses only. Don’t leave it open to the entire internet.

Set the default policy to deny all other incoming traffic.

This approach is more secure than managing iptables or ufw directly on the server because the firewall rules are applied at the network level, before traffic even reaches your VPS.

Step 7: Test with a simple application

Create a quick test to make sure everything works:

mkdir ~/node-test && cd ~/node-test

Create a file called 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

Run it:

node app.js

If you’ve opened port 3000 in your firewall, you can access http://your-server-ip:3000 in a browser.

Press Ctrl+C to stop the server.

Next steps

Now that Node.js is installed, you might want to:


Explore our VPS plans to find the right server for your Node.js application.