Linux VPS

Install Node.js and npm on a Linux VPS (nvm or NodeSource)

Install a current LTS version of Node.js and npm on Ubuntu, Debian, AlmaLinux or Rocky Linux using nvm or the NodeSource repository, and verify it works.

BeginnerLinux VPS3 min read

Most Linux distributions ship an old Node.js in their default repositories. To run modern apps such as Next.js you need a current LTS release. This guide shows the two reliable ways to install it on a VPS: nvm (per user, easy to switch versions) and NodeSource (system-wide packages).

Before you start

  • A Linux VPS running Ubuntu 22.04/24.04, Debian 12, AlmaLinux 8/9 or Rocky Linux 8/9.
  • SSH access as root or a sudo user. See Connect to a Linux VPS over SSH.
  • The Node.js major version your project needs (check engines in package.json).

Which method should you choose?

MethodBest forNotes
nvmOne app user, several projects, easy upgradesInstalled in the user's home folder; not visible to other users or system services by default
NodeSourceServers where systemd or several users need /usr/bin/nodeUpdates with the normal package manager

Option A: install Node.js with nvm

  1. Log in as the user that will run the app (not root, ideally).
  2. Download and run the nvm install script from the official nvm-sh repository:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
  3. Load nvm in the current shell (or log out and back in):
    source ~/.bashrc
  4. Install and use the latest LTS release:
    nvm install --lts
    nvm alias default lts/*
  5. To install a specific major version instead, for example 22:
    nvm install 22

Note: nvm installs Node.js under ~/.nvm. Tools like PM2 must be installed with the same user so they find the right node binary.

Option B: install Node.js from NodeSource

Ubuntu and Debian

  1. Install the prerequisites and add the repository for your chosen major version (22 here):
    sudo apt update
    sudo apt install -y curl ca-certificates
    curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
  2. Install Node.js (npm is included):
    sudo apt install -y nodejs

AlmaLinux and Rocky Linux

  1. Add the repository:
    curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
  2. Install Node.js:
    sudo dnf install -y nodejs

Install build tools for native modules

Some npm packages (for example bcrypt or sharp on older versions) compile native code. Install a compiler toolchain so npm install does not fail:

sudo apt install -y build-essential

On AlmaLinux or Rocky Linux use sudo dnf groupinstall -y "Development Tools".

Check that it works

node -v
npm -v
which node

You should see the version you installed, for example v22.x.x. Then try a one-line server:

node -e "require('http').createServer((q,r)=>r.end('ok')).listen(3000)"

In a second SSH session run curl http://127.0.0.1:3000; it should print ok. Press Ctrl+C to stop the test server.

Troubleshooting

  • nvm: command not found — open a new shell or run source ~/.bashrc. Check that the installer added the nvm lines to ~/.bashrc or ~/.profile.
  • Old version still shows — another Node.js from the distro repository is earlier in PATH. Remove it with sudo apt remove nodejs and reinstall.
  • EACCES on global installs — with NodeSource, use sudo npm install -g, or switch to nvm so globals live in your home folder.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.