Install Node.js with nvm on a Linux VPS
Guide to installing Node.js on a Linux VPS at Lordhosting with nvm: version management, the NodeSource alternative, npm basics and keeping an app running 24/7 with PM2.
Node.js powers countless server-side tools: Discord bots, APIs, web apps, automation scripts. On a VPS, the most flexible approach is to install it with nvm, which manages several versions without root rights. This guide covers the installation, the NodeSource alternative, npm basics, and how to keep an app running 24/7.
⚙️ Requirements
- A Lordhosting VPS (Debian or Ubuntu)
- SSH access with a non-root user — see Secure a Linux VPS
⚙️ 1. Install nvm
Download and run the official install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
Reload your shell to enable the command:
source ~/.bashrc
Check:
nvm --version
⚙️ 2. Install Node.js with nvm
Install the latest LTS version and make it the default:
nvm install --lts
nvm alias default 'lts/*'
To install a specific version or switch:
nvm install 20 # installs Node 20
nvm use 20 # switches to Node 20 for the session
nvm ls # lists installed versions
Put an .nvmrc file containing the version number at the root of a project, then run nvm use: nvm automatically selects the right version.
⚙️ 3. Alternative: the NodeSource repository
For a system-wide installation (useful for services started by systemd), NodeSource provides an up-to-date package:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
⚙️ 4. Verify and npm basics
node -v # Node version
npm -v # npm version
A few useful npm commands:
npm init -y # creates a package.json
npm install express # adds a dependency
npm run <script> # runs a script defined in package.json
npm ci # installs exactly the package-lock (deployment)
⚙️ 5. Keep an application online with PM2
A node app.js stops the moment you close SSH. PM2 restarts the app after a crash and on VPS reboot:
npm install -g pm2
pm2 start app.js --name my-app
pm2 startup # generates the systemd service (follow the printed line)
pm2 save # remembers the processes to restart on boot
Common commands:
pm2 list # application status
pm2 logs my-app # follow logs
pm2 restart my-app # restart
✅ Conclusion
You now have Node.js installed and cleanly managed with nvm, npm at hand, and an application kept online 24/7 by PM2. That is the ideal base to host a Discord bot, an API or a small web app on your VPS.
Need a server to host your Node apps? Our high-performance Ryzen VPS, KVM-based, are delivered in minutes with full root access.
❗Always good to know

