ACLClouds
ACLClouds

How do I install Node.js on an Ubuntu or Debian VPS?

Install a recent LTS release of Node.js with NodeSource or nvm on Ubuntu 24.04 and Debian 12, keep the application online with PM2 and start it again when

The nodejs package from the official repositories installs Node.js 18 on Ubuntu 24.04 as well as on Debian 12, a release that has had no fixes since April 2025. For an application or a bot in production, install an LTS release: Node.js 26 is the active LTS on 17 November 2026, and Node.js 24 is still maintained. The commands in this guide were tested on Ubuntu 24.04 and Debian 12.

Step-by-step procedure

  1. Choose the method

    NodeSource adds an APT repository: one version for the whole system, updated with apt upgrade. nvm installs Node.js in a user’s folder and lets you keep several versions side by side. For a single service, NodeSource is enough; for several projects on different versions, take nvm.

  2. Install with NodeSource

    As root, download the setup_26.x script, read it if you wish, run it with bash, then run apt install -y nodejs. The package already includes npm: do not also install the distribution’s npm package.

  3. Or install with nvm

    Logged in as the user who will run the application, first install curl and libatomic1, then run the nvm v0.41.0 install script. Reload the shell with source ~/.bashrc, then nvm install --lts installs the latest LTS and makes it the default.

  4. Check the versions

    node -v should show v26 followed by the patch number and npm -v a version 11. If node -v still shows v18, the old distribution package comes first: which node shows the binary in use.

  5. Run the application with PM2

    Install PM2 with npm install -g pm2, go to the project folder, then run pm2 start index.js --name app. PM2 restarts the process if it crashes; pm2 logs app shows its output and pm2 restart app restarts it after a code update.

  6. Start again when the VPS boots

    pm2 startup creates a systemd service; with a non-root user, it prints a sudo env PATH= command to copy as is. Then run pm2 save to record the list of processes that PM2 will bring back after a reboot.

Node.js 26 LTS with NodeSource (root)

apt update && apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_26.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt install -y nodejs
node -v
npm -v

Node.js with nvm (application user)

sudo apt install -y curl libatomic1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash
source ~/.bashrc
nvm install --lts
nvm install 24
nvm alias default 26
nvm ls

PM2: start, follow and restart at boot

npm install -g pm2
cd ~/app
pm2 start index.js --name app
pm2 list
pm2 logs app --lines 50
pm2 startup
pm2 save

Before you start

You need SSH access to the VPS and a user dedicated to the application rather than root: adduser app creates it. If apt install nodejs was already run, remove that old release with apt remove nodejs before moving to NodeSource or nvm, so that two binaries do not compete.

  • A simple Node.js application or a Discord bot runs with less than 200 MB of RAM; installing the dependencies with npm needs more for a few seconds.
  • The engines field of package.json or a .nvmrc file states the version the project expects.

Several versions with nvm

nvm install 24 adds Node.js 24 next to 26, nvm use 24 switches the current shell and nvm alias default 26 picks the version for new shells. In a folder that holds a .nvmrc file with 24, nvm use without an argument loads the right version. Versions installed by nvm live in ~/.nvm: they only exist for that user, and a systemd service or a cron job must call the full path of the binary, or go through PM2.

Open the application to the Internet

A Discord bot needs no incoming port: it connects to Discord itself. An API or a website, on the other hand, listens on a port such as 3000. The cleanest way is to keep it on 127.0.0.1 and put Nginx in front, with a Let’s Encrypt certificate; otherwise, open the port in UFW and in the panel firewall.

Common errors and fixes

Most errors come from a Node.js release other than the expected one, or from a shell that did not load nvm.

  • nvm: command not found right after installing: the shell has not read ~/.bashrc yet. Run source ~/.bashrc or open a new SSH session.
  • node: error while loading shared libraries: libatomic.so.1 with nvm: the library is missing on a minimal install. apt install libatomic1 fixes the error, without reinstalling Node.js.
  • npm ERR! code EACCES on npm install -g: the global folder belongs to root. With NodeSource, install global tools as root; with nvm, run the command without sudo.
  • SyntaxError: Unexpected token or ERR_REQUIRE_ESM at startup: the project expects a newer release. Compare node -v with the engines field of package.json.
  • The application does not come back after a VPS reboot: pm2 save was not run after the last pm2 start, or the command printed by pm2 startup was not executed.

VPS or bot hosting?

For a single Discord bot in Node.js, ACLClouds bot hosting avoids this whole setup: you upload the code, the panel installs the dependencies, runs the bot 24/7 and restarts it if it crashes. The free plan (315 MB of RAM) accepts Node.js and Python; the Starter plan costs €2.99 per month, or €2.39 per month with a one-year commitment (prices on 17 November 2026).

A VPS makes sense for several applications, an API with its database or a need for full control. The VPS Mini (2 vCPU, 8 GB of RAM, 40 GB of storage) costs €4.99 per month without commitment, or €3.99 per month with a one-year commitment, with a network of up to 1 Gbit/s.

Quick check

  • node -v shows an LTS release (v26 or v24).
  • pm2 list shows the application as online.
  • The application comes back on its own after a VPS reboot.
  • The application does not run as root.

Frequently asked questions

Why not install Node.js with apt install nodejs?

The Ubuntu 24.04 and Debian 12 repositories ship Node.js 18, whose support ended in April 2025, and many recent libraries, such as Vite 8 or ESLint 10, require a newer release. NodeSource or nvm install a maintained LTS.

NodeSource or nvm: which one should I choose?

NodeSource suits a server that runs a single application: Node.js is available to every user and is updated with the rest of the system. nvm suits several projects that need different versions, or testing a new version without touching the one in production.

How do I update Node.js to a new LTS?

With NodeSource, apt upgrade applies the fixes of the same major version; to change major version, run the script of the new version again, then apt install nodejs. With nvm, nvm install --lts --reinstall-packages-from=current installs the new LTS and copies the global packages, PM2 included, into it. Then restart the application and check its logs.

PM2 or systemd to keep the application online?

Both restart the process after a crash and when the VPS boots. PM2 is simpler for several Node.js applications, with pm2 list, pm2 logs and cluster mode; systemd adds no tool and suits a single service. Avoid combining both for the same application.