Node.js is a powerful runtime for running JavaScript outside the browser, perfect for scalable web apps. PM2, a process manager for Node.js, ensures uptime and simplifies management. This guide walks you through installing Node.js and PM2 on an AvaHost Ubuntu VPS (20.04/22.04/24.04), with practical examples to deploy and manage applications efficiently.
AvaHost VPS with Ubuntu 20.04, 22.04, or 24.04.
Root access or sudo
privileges (see prior SSH guide).
Basic Linux command knowledge.
A static IP or domain (e.g., app.yourdomain.com
).
Before installing Node.js and PM2, update your package list to ensure you have the latest versions available:
sudo apt update && sudo apt upgrade -y
There are multiple ways to install Node.js on Ubuntu 20.04. We will use the NodeSource repository to get the latest stable version.
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
Replace 18.x
with the latest LTS version if necessary.
sudo apt install -y nodejs
node -v
npm -v
This should output the installed versions of Node.js and npm.
PM2 is a process manager that helps keep your Node.js applications running.
sudo npm install -g pm2
pm2 -v
This should return the installed version of PM2.
To demonstrate PM2, we will create a simple Node.js application and run it.
mkdir myapp && cd myapp
echo "console.log('Hello from Node.js!');" > app.js
pm2 start app.js
pm2 list
pm2 save
pm2 startup
Follow the instructions provided by the command to complete the setup.
PM2 provides various commands to manage and monitor applications:
pm2 restart app.js
pm2 stop app.js
pm2 delete app.js
pm2 logs
Installing Node.js and PM2 on an AvaHost Ubuntu VPS is simple and enables robust app management. The examples, like running app.js
with PM2 or setting up Nginx, ensure your apps are scalable and reliable. With AvaHost’s high-performance infrastructure, you can deploy Node.js applications with confidence, ensuring uptime and easy monitoring. Explore PM2’s features (man pm2
) and AvaHost’s VPS plans to power your projects.