How Do I Install Node.js on My VPS?
Node.js is a runtime that lets you run JavaScript applications on your server. npm is the package manager commonly used together with Node.js.
In this article, we explain how to install Node.js and npm on a Linux VPS using NVM.
Node.js is a runtime that lets you run JavaScript applications on your server. npm is the package manager commonly used together with Node.js.
What do you need?
- A Linux VPS, for example Ubuntu 22.04 or Ubuntu 24.04
- SSH access to your VPS
- A user with sudo privileges
Tip: Logging in through SSH is usually easier than using VNC. If you cannot connect through SSH, you can temporarily use VNC by following the article Enabling VNC on Your VPS.
Installing Node.js with NVM
NVM stands for Node Version Manager. It lets you easily install multiple Node.js versions and switch between them.
- Connect to your VPS through SSH:
ssh user@your-vps-ip
If you use root, that would be:
ssh root@your-vps-ip
- Update the package list and install the required tools:
sudo apt update
sudo apt install -y curl ca-certificates
- Install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.7/install.sh | bash
- Reload NVM in your terminal:
source ~/.bashrc
If this does not work, log out and log back in through SSH.
- Install the latest LTS version of Node.js:
nvm install --lts
nvm use --lts
At the moment, Node.js 24 LTS is the current LTS version. If your application specifically requires Node.js 22, use:
nvm install 22
nvm use 22
- Check whether Node.js and npm were installed correctly:
node -v
npm -v
If you see version numbers, Node.js has been installed correctly.
Use Node.js by default
Do you want the same Node.js version to be used by default in new SSH sessions? Set a default version:
nvm alias default node
Or choose Node.js 24 specifically:
nvm alias default 24
For server applications
Do you want to keep a Node.js app running in the background? You can use PM2:
npm install -g pm2
pm2 start app.js
pm2 save
Replace app.js with the start file of your application.
Troubleshooting
If something does not work, first check:
- whether you logged in again after installing NVM;
- whether you ran
source ~/.bashrc; - whether you are using the correct Node.js version with
node -v; - whether you have enough permissions to run the commands;
- whether your application supports the selected Node.js version.
If you need help, feel free to reach out via Discord or create a support ticket.
