How to Install Node.js 22 LTS on Ubuntu 24.04 VPS

Node.js is a fast and scalable JavaScript runtime used to build APIs, web applications, real-time services, and automation tools. The latest Long-Term Support (LTS) version is recommended for production VPS servers because it receives regular security updates and long-term maintenance.

Requirements

  • Ubuntu 24.04 VPS
  • Root or sudo privileges
  • SSH access

Step 1 — Update Your Server

sudo apt update
sudo apt upgrade -y

Step 2 — Install Required Packages

sudo apt install curl ca-certificates -y

Step 3 — Add the NodeSource Repository

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -

Step 4 — Install Node.js

sudo apt install nodejs -y

Step 5 — Verify Installation

Check the installed Node.js version:

node -v

Example output:

v22.x.x

Check the installed npm version:

npm -v

Step 6 — Create a Test Application

mkdir myapp
cd myapp
nano app.js

Add the following code:

console.log("Hello from VPS For Life!");

Save the file and run it:

node app.js

You should see:

Hello from VPS For Life!

Step 7 — Update npm (Optional)

sudo npm install -g npm@latest

Useful Commands

node -v
npm -v
npm install
npm update
npm uninstall package-name
npm list

Install PM2 for Production

PM2 helps keep Node.js applications running continuously.

sudo npm install -g pm2

Check the version:

pm2 -v

Start your application:

pm2 start app.js

Enable PM2 to start automatically after reboot:

pm2 startup
pm2 save

Best Practices

  • Use the latest LTS version of Node.js.
  • Run applications with PM2 in production.
  • Keep npm packages updated regularly.
  • Avoid running applications as the root user.
  • Use Nginx as a reverse proxy for better security and performance.

Conclusion

Node.js 22 LTS provides excellent performance, security, and stability for modern web applications. Combined with Nginx and PM2, it creates a reliable environment for hosting APIs, websites, and backend services on your VPS.


Related Articles

  • How to Install Nginx on Ubuntu 24.04 VPS
  • How to Install Docker on Ubuntu 24.04 VPS
  • How to Install Docker Compose on Ubuntu VPS
  • How to Secure Your Linux VPS
  • How to Connect to Your VPS via SSH
  • node.js
  • 1 Los Usuarios han Encontrado Esto Útil
¿Fue útil la respuesta?

Artículos Relacionados

How to Change Your SSH Port for Better Security

By default, SSH runs on port 22, which is commonly targeted by automated attacks. Changing the...

How to Connect to Your VPS via SSH

SSH (Secure Shell) is a protocol used to securely connect to your VPS. Follow the steps below to...

How to Update and Upgrade Your VPS

Keeping your VPS up to date is essential for security and performance. Here’s how to update and...

How to Check Your VPS Resource Usage

Monitoring your VPS resource usage helps you keep your server performing well. Here’s how you can...

How to Reboot Your VPS Safely

<p>Sometimes, you need to reboot your VPS to apply updates or fix issues. Here’s how to do...