TutorialsAugust 4, 20264 min read

How to Install Node.js on a VPS with NVM

Install Node.js the right way using NVM so you can switch versions per project, update painlessly, and avoid sudo-npm headaches.

NBy Nxeon

Installing Node.js from Ubuntu's default apt repository gives you an old version and locks you to it. NVM (Node Version Manager) is the better path: it installs Node in your home directory, lets you run multiple versions side by side, and means you never need sudo for npm install -g. This guide sets up NVM on a fresh Ubuntu 24.04 VPS.

Why NVM instead of apt?

The nodejs package in Ubuntu 24.04 lags behind the current LTS, and upgrading it later is awkward. NVM solves three problems at once:

  • Install any Node version, including the latest LTS, in seconds.
  • Switch versions per project so an old app and a new one coexist.
  • Avoid the permission mess of global installs owned by root.

If you would rather not manage Node yourself at all, Nxeon offers managed Node.js hosting — but doing it with NVM keeps you in full control.

Install NVM

Run the official install script (check the NVM GitHub releases for the current version tag):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

The script appends NVM's loader to your ~/.bashrc. Reload your shell so nvm becomes available:

source ~/.bashrc
nvm --version

Install Node.js

Install the latest long-term-support release and make it the default:

nvm install --lts
nvm alias default 'lts/*'
node --version
npm --version

That is it — you have Node and npm without touching sudo. LTS releases get years of security updates, which is exactly what you want on a server.

The Nxeon game-server control panel — live console, player slots, and TPS
The Nxeon game-server control panel — live console, player slots, and TPS

Manage multiple versions

This is where NVM earns its keep. Install specific versions and switch between them:

nvm install 20
nvm install 22
nvm use 20
nvm ls

To pin a project to a version, drop a .nvmrc file in its root containing just the version (for example 22). Then nvm use inside that directory reads it automatically.

Test with a tiny server

Confirm everything works with a one-file HTTP server:

mkdir ~/hello && cd ~/hello
cat > server.js <<'EOF'
const http = require('http');
http.createServer((req, res) => res.end('Node is live on Nxeon\n'))
  .listen(3000, '127.0.0.1');
console.log('Listening on 127.0.0.1:3000');
EOF
node server.js

In another SSH session, curl http://127.0.0.1:3000 should print the message. Note it binds to 127.0.0.1 — you never expose Node directly to the internet; you put a reverse proxy in front.

From here to production

Running node server.js in your terminal stops the moment you disconnect. For anything real you need a process manager that restarts the app on crash and on reboot. That is exactly what deploying a Node.js app with PM2 covers, and you will front it with an Nginx reverse proxy. If you are deploying a full framework, see how to deploy a Next.js app to a VPS.

Handy global tools and housekeeping

With NVM in place, global installs are painless and need no sudo. A few tools worth having on a dev server:

npm install -g pm2 npm-check-updates serve

pm2 keeps apps alive, npm-check-updates bumps your dependencies, and serve spins up a quick static file server to test a build. Because these live inside the active Node version, switching with nvm use swaps the whole toolchain — global packages are per-version, which occasionally surprises people.

To keep the server tidy, prune Node versions you no longer use:

nvm ls
nvm uninstall 20

And clear npm's cache if disk space gets tight:

npm cache clean --force

Keeping a single LTS as your default, with the odd extra version for testing, keeps things predictable across deploys.

FAQ

Should I ever use sudo with npm after installing NVM?

No. NVM installs Node under your home directory, so global packages install without root. If you find yourself typing sudo npm, something is misconfigured — you are probably falling back to a system Node.

How do I update Node to a newer LTS later?

Run nvm install --lts again to grab the new release, then nvm alias default 'lts/*'. You can reinstall global packages from the old version with nvm install --lts --reinstall-packages-from=default.

Does NVM work for other users on the server?

NVM is per-user by design — each user installs it in their own home. For a shared system-wide Node, a deb from NodeSource is simpler, but per-user NVM is safer and more flexible for deployments.

Why does 'nvm: command not found' appear after I install it?

Your shell has not re-sourced ~/.bashrc. Run source ~/.bashrc or open a new SSH session. If it still fails, confirm the NVM block was actually appended to your shell rc file.

Nxeon VPS hosting for developers ships a clean Ubuntu 24.04 base with full root and fast NVMe, so NVM and your Node apps run without fighting the platform.

#nodejs#nvm#vps#ubuntu#javascript#seobatch

Deploy your first server in under a minute

Creating an account is free and takes no card details. You pay when you deploy — choose a billing term and pay from your wallet or by card at checkout.