Skip to content

Web serverFor beginnersDuration around 10 min.

How to install Node.js on Ubuntu: current LTS with NodeSource or nvm

The Node.js packages from Ubuntu are solid but older. This tutorial installs the current LTS version via NodeSource or nvm and sets up an application as a service that restarts automatically after a crash.

Tested on with Node.js 26.14 and nvm 0.41 on Ubuntu 24.04 LTS and Ubuntu 26.04 LTS

At a glance

  • Ubuntu itself provides Node.js 18 (24.04) and 22 (26.04); the current LTS is Node.js 26.
  • NodeSource provides one version for the entire server and keeps it up to date with apt; nvm allows multiple versions per user.
  • As a systemd service, the application starts with the server and restarts after a crash.

Prerequisites

  • A server running Ubuntu 24.04 or 26.04 and a user with sudo privileges โ€” such as a VPS or a Cloud Server.
  • curl is installed on most servers, otherwise with sudo apt install -y curl.

Which approach is right?

  • NodeSource: one version for the entire server, updates with apt. The right approach for an application running as a service.
  • nvm: multiple versions side by side, per user and without sudo. Good for development and projects with different versions.
  • Ubuntu package: without a third-party repository, but with an older version.

1. Current LTS via NodeSource

The NodeSource script sets up the repository for Node.js 26; then apt installs the nodejs package with npm.

Install Node.js 26
curl -fsSL https://deb.nodesource.com/setup_26.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
Check version
node -v
npm -v
Output
v26.14.0
11.21.3

2. Multiple versions with nvm

nvm installs itself in your home directory. The second line loads it into the current session; this happens automatically on the next login.

The current LTS with nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash
source ~/.nvm/nvm.sh
nvm install --lts

Install another version, switch, and set the default for new sessions:

Switch versions
nvm install 22
nvm use 22
nvm alias default lts/*
nvm ls

3. Alternative: the Ubuntu package

Ubuntu 24.04 provides Node.js 18, Ubuntu 26.04 Node.js 22. For an application that expects exactly this version, the package from the Ubuntu repository is sufficient:

Node.js from Ubuntu
sudo apt install -y nodejs npm

4. Start first application

A small application shows that everything is running. Create the file:

~/app/server.js
const http = require("node:http");
http.createServer((req, res) => res.end("Hallo von Node.js\n")).listen(3000, "127.0.0.1");
Start and access
mkdir -p ~/app && cd ~/app
nano server.js
node server.js &
curl http://127.0.0.1:3000

The application only listens on 127.0.0.1. You can make it accessible from the outside with a reverse proxy โ€” the tutorial Nginx as a reverse proxy shows how.

5. Run as a systemd service

Stop the application from step 4 and create a unit. Adjust User and WorkingDirectory to your user.

/etc/systemd/system/app.service
[Unit]
Description=Node.js-Anwendung
After=network.target
 
[Service]
Type=simple
User=anna
WorkingDirectory=/home/anna/app
ExecStart=/usr/bin/node server.js
Restart=on-failure
Environment=NODE_ENV=production
 
[Install]
WantedBy=multi-user.target
Set up and start service
sudo nano /etc/systemd/system/app.service
sudo systemctl daemon-reload
sudo systemctl enable --now app
systemctl status app

Restart after crash

Restart=on-failure restarts the application if it crashes. Its output is in the system log: journalctl -u app.

Typical errors

  • Library libatomic.so.1 missing: On slim Ubuntu 26.04 images, a library required by the Node.js version of nvm is missing. Install it with sudo apt install -y libatomic1.
The message
node: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory
  • nvm: command not found: The session does not know nvm yet. Log in again or load ~/.nvm/nvm.sh as in step 2.
  • Service cannot find node: A version installed with nvm is located in the home directory, not under /usr/bin. For a service, use NodeSource or enter the full path from which node.
  • EADDRINUSE: The port is in use, usually by a second instance of the application. Stop it or choose a different port.

We tested all commands in this guide on 2 December 2026 โ€” with Node.js 26.14 and nvm 0.41 on Ubuntu 24.04 LTS and Ubuntu 26.04 LTS. If a step changes at the manufacturer, we update it here along with the date.

Official documentation

Frequently asked questions about Node.js

Which Node.js version should I use?

For a server, the current LTS version, in December 2026 Node.js 26. LTS versions receive security updates for years, the odd versions only for a few months.

Do I need to install npm separately?

Not with NodeSource and nvm, npm is included. With the Ubuntu package, you install npm as a separate package.

How do I update Node.js?

With NodeSource via apt like any other package. With nvm, you install the new version and make it the default.

Should the application run as root?

No. A dedicated user without special privileges limits the damage if the application is attacked; the unit defines it with User.

How do I make the application accessible on port 80 or 443?

Via a reverse proxy such as Nginx, which also handles the TLS certificate. The application itself remains on a high port and on 127.0.0.1.

Further reading

More tutorials

  • How to set up Nginx as a reverse proxy with HTTPS (Letโ€™s Encrypt)

    Web serverFor beginnersabout 20 min

    Following this tutorial, Nginx will accept requests to your domain, pass them to an application on the same server, and serve everything over HTTPS with a Letโ€™s Encrypt certificate. This is suitable for Node.js, Python, Go, or a container listening on a local port.

  • How to install WordPress on your own server: Nginx, PHP and MariaDB

    Web serverFor advanced usersabout 30 min

    This tutorial brings WordPress to your own server with Ubuntu: Nginx as the web server, PHP-FPM for WordPress, MariaDB as the database and a certificate from Letโ€™s Encrypt. Finally, you will complete the setup in the browser, where you create the title and administrator.

A server for your application

On a VPS or Cloud Server, your Node.js application runs as a service โ€” behind Nginx with TLS.