How To Install Node.js on Ubuntu 26.04 LTS

Install Node.js on Ubuntu 26.04

Ubuntu 26.04 LTS, codenamed Resolute Raccoon, is a long-term-support release built for servers, development workstations, containers, and production web workloads. If you are deploying a JavaScript application, API, build pipeline, or automation tool, installing Node.js correctly matters more than simply running apt install nodejs. The right installation method affects version stability, security updates, npm behavior, and how cleanly you can upgrade later.

Node.js is the JavaScript runtime that executes server-side JavaScript outside a browser. It ships with npm, the default package manager, and supports modern web frameworks such as Express, NestJS, Next.js, Astro, and Fastify. On Ubuntu, there is rarely one universally correct installation route. A small VPS running one application has different requirements from a developer laptop managing several projects or a production cluster that must remain predictable during deployments.

This guide covers the three practical approaches: Ubuntu’s default repositories, NodeSource for a system-wide managed runtime, and NVM for per-user version control. It also includes verification steps, production hardening, troubleshooting, and performance tuning. The commands are written for Ubuntu 26.04 LTS, but most also apply to recent Debian-based systems.

Choose the Right Installation Method

Before touching the terminal, decide how Node.js should be owned and upgraded on the machine. This decision prevents many of the version conflicts and permission problems that appear later.

Method Best for Version control System-wide Production suitability
Ubuntu APT repository Simple servers, scripts, baseline installs Controlled by Ubuntu Yes Good for stable, conservative setups
NodeSource APT repository Production servers needing a specific major Node.js version You select the major line Yes Excellent when paired with pinned versions
NVM Developers, CI runners, multi-project machines Per-user and per-project No Good for development; use carefully in production
Official binary tarball Containers, air-gapped systems, custom deployments Fully explicit Depends on placement Excellent for immutable deployments

Ubuntu’s default packages are suitable when you want a dependable runtime maintained through the distribution’s package lifecycle. NodeSource is useful when your application requires a newer Node.js release line than the distribution provides. NVM is ideal when several projects need different versions, but it installs Node.js in a user’s home directory, which is not always the cleanest choice for a shared production service account.

A useful rule: use one installation method per server. Mixing Ubuntu’s nodejs package, NodeSource, and NVM on the same machine creates ambiguous PATH resolution and makes incident troubleshooting unnecessarily painful.

Prepare Ubuntu 26.04 LTS

Start from a clean, updated system. On a fresh VPS, this also confirms that APT, networking, DNS, and repository access are working before you introduce a new package source.

Update the package index and upgrade installed packages:

sudo apt update
sudo apt upgrade -y

Install the tools required by most installation methods:

sudo apt install -y ca-certificates curl gnupg

ca-certificates allows secure HTTPS connections, curl downloads files and repository setup scripts, and gnupg supports GPG key verification. These packages are small, but omitting them is a common cause of failed repository setup on minimal server images.

Check the Ubuntu release and architecture:

lsb_release -a
uname -m

You should see Ubuntu 26.04 and either x86_64 for standard 64-bit Intel or AMD hardware, or aarch64 for ARM systems. Node.js provides Linux builds for both architectures, so confirm this before downloading binaries manually. The official Node.js download archive provides separate Linux x64 and ARM64 packages. [16][18]

Install Node.js From Ubuntu Repositories

The simplest approach is to install Node.js directly from Ubuntu’s repositories:

sudo apt install -y nodejs npm

Verify the installation:

node --version
npm --version

Example output:

v22.22.1
9.2.0

The exact version depends on the packages available in Ubuntu’s archive when you install. On Ubuntu 26.04, the distribution’s Node.js package is based on the Node.js 22 maintenance LTS line, while npm is packaged separately. [14]

This method is appropriate when:

  • You need Node.js for a simple utility or internal script.
  • Your application explicitly supports the version available from Ubuntu.
  • You prefer packages managed entirely through Ubuntu’s normal update process.
  • You do not need to select a particular Node.js major version.

It is less suitable when your application requires a newer runtime, a specific LTS branch, or tight control over the Node.js version deployed across several servers.

When APT Is the Right Choice

For a small internal tool, a cron-driven Node.js script, or a server where the application has already been tested against the distribution’s Node.js version, the Ubuntu repository is often the least complicated path. Updates arrive through the same apt upgrade workflow used for the rest of the operating system.

That predictability has value. In production, “newest” is not automatically better. A version that is consistent across staging and production, backed by a tested deployment process, usually beats a newer runtime that introduces unexpected dependency behavior.

Install a Specific Node.js Version With NodeSource

NodeSource maintains APT repositories for supported Node.js release lines. This is the preferred system-wide approach when you need Node.js 22, 24, or 26 and want package-manager-based updates rather than manually replacing binaries. NodeSource currently provides repositories for Node.js 22.x, 24.x, and 26.x. [8][11]

Before running a setup script as root, download and inspect it. Piping an unreviewed script directly into a privileged shell is convenient, but it is not the habit of a careful systems administrator.

curl -fsSL https://deb.nodesource.com/setup_24.x -o nodesource_setup.sh
less nodesource_setup.sh

Review the script, especially the repository URL, GPG key handling, and any changes it makes under /etc/apt. Once you are satisfied, run it:

sudo -E bash nodesource_setup.sh

Refresh APT metadata and install Node.js:

sudo apt update
sudo apt install -y nodejs

With NodeSource, npm is bundled inside the nodejs package. Do not install the separate Ubuntu npm package at the same time; doing so can create a conflicting package set.

Verify the result:

node --version
npm --version

To install a different major version, replace 24.x in the setup URL with the desired release line:

curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt update
sudo apt install -y nodejs

For Node.js 26:

curl -fsSL https://deb.nodesource.com/setup_26.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt update
sudo apt install -y nodejs

Node.js 24 is identified as the Krypton LTS line, while Node.js 22 remains a maintenance LTS branch. The official Node.js site also lists Node.js 26 as an LTS release line, so choose based on your application’s compatibility matrix rather than release marketing alone. [17][18][21]

Manual NodeSource Repository Setup

Some administrators prefer explicit repository configuration over a setup script. It makes changes easier to audit in configuration management tools such as Ansible, Salt, or Terraform.

Install prerequisites:

sudo apt update
sudo apt install -y ca-certificates curl gnupg

Create the keyring directory and import NodeSource’s signing key:

sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
  | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

Create the repository definition. This example targets Node.js 24:

echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" \
  | sudo tee /etc/apt/sources.list.d/nodesource.list

Update and install:

sudo apt update
sudo apt install -y nodejs

This approach gives you a clear, inspectable record of exactly which repository and signing key the server trusts. In an environment with configuration drift, that transparency is worth the extra minute.

Install Node.js With NVM

NVM, or Node Version Manager, installs Node.js in a user’s home directory and allows fast switching between versions. It is particularly useful on development machines, CI build agents, and workstations where projects rely on different Node.js versions.

Install NVM for your current user:

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

Close and reopen the terminal, or load the updated shell configuration:

source ~/.bashrc

Confirm that NVM is available:

command -v nvm

Install the latest LTS release:

nvm install --lts
nvm use --lts
nvm alias default lts/*

Check the active versions:

node --version
npm --version

To install a specific version:

nvm install 22
nvm use 22

To install another version without switching immediately:

nvm install 24

List installed versions:

nvm ls

NVM does not require root privileges because it installs under the user’s home directory. That isolation is convenient, but it also means each user account may have its own Node.js installation. On a production server, this can complicate systemd services, logging, upgrades, and incident response.

NVM in Production: Use It Carefully

NVM is excellent for developers. For a production service, it can still work, but the service user must have the correct NVM environment loaded. A systemd unit does not automatically source ~/.bashrc, so a Node.js binary installed through NVM may not be found when the service starts.

If you use NVM on a server, either:

  • Configure the systemd unit with an explicit Environment=PATH=... value.
  • Create a symlink to the selected Node.js binary in a stable location.
  • Use NodeSource or an official binary deployment instead.

The second option is often the cleanest compromise:

sudo ln -s /home/deploy/.nvm/versions/node/v24.22.2/bin/node /usr/local/bin/node
sudo ln -s /home/deploy/.nvm/versions/node/v24.22.2/bin/npm /usr/local/bin/npm

Avoid linking binaries owned by a regular user into system paths if that user account can be compromised. For a dedicated production service, a system-managed NodeSource installation is usually safer and simpler.

Verify the Node.js Installation

Version output alone does not prove that Node.js can compile native modules, resolve packages, or run an HTTP server. Run a quick functional test.

Create a test directory:

mkdir -p ~/nodejs-test
cd ~/nodejs-test
npm init -y

Create a minimal HTTP server:

cat > server.js <<'EOF'
const http = require('node:http');

const server = http.createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({ status: 'ok', node: process.version }));
});

server.listen(3000, '127.0.0.1', () => {
  console.log('Node.js test server listening on http://127.0.0.1:3000');
});
EOF

Run it:

node server.js

In another terminal, test it:

curl http://127.0.0.1:3000

Expected output:

{"status":"ok","node":"v24.22.2"}

Stop the test server with Ctrl+C. This test confirms that the runtime starts, binds to a local port, and handles a request. It does not test native modules, but it catches the most common installation failures.

Run Node.js as an Unprivileged Service User

Never run a public-facing Node.js application as root. If the application or one of its dependencies is compromised, running as root gives an attacker far more access than necessary.

Create a dedicated system user:

sudo adduser --system --group --home /opt/myapp --shell /usr/sbin/nologin myapp

Create the application directory and assign ownership:

sudo mkdir -p /opt/myapp
sudo chown -R myapp:myapp /opt/myapp

Deploy the application, then install dependencies as the service user:

sudo -u myapp bash -c 'cd /opt/myapp && npm ci --omit=dev'

Use npm ci rather than npm install for reproducible deployments. It installs dependencies strictly from package-lock.json, which reduces the chance that a deployment pulls in unexpected package versions.

Check the installed dependency tree:

sudo -u myapp bash -c 'cd /opt/myapp && npm ls --depth=0'

Create a Systemd Service

A production Node.js process should restart after failure, start on boot, and log to journald. Systemd handles all three.

Create the service unit:

sudo nano /etc/systemd/system/myapp.service

Use a configuration similar to this:

[Unit]
Description=My Node.js application
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=myapp
Group=myapp
WorkingDirectory=/opt/myapp
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=3
Environment=NODE_ENV=production
Environment=PORT=3000

# Security hardening
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
ReadWritePaths=/opt/myapp

# Resource controls
MemoryMax=1G
TasksMax=512

[Install]
WantedBy=multi-user.target

Adjust ExecStart to match your application entry point. If Node.js was installed through NVM, replace /usr/bin/node with the absolute path returned by:

which node

Reload systemd and start the service:

sudo systemctl daemon-reload
sudo systemctl enable --now myapp.service

Check its status and logs:

sudo systemctl status myapp.service
sudo journalctl -u myapp.service -f

Restart=always is appropriate for many Node.js services, but do not treat it as a substitute for monitoring. If the application crashes repeatedly, systemd will keep restarting it, potentially masking an underlying dependency, configuration, or memory problem.

Firewall and Network Security

Node.js applications should generally listen on 127.0.0.1 or a private interface, with Nginx, Caddy, or a load balancer handling public HTTPS traffic. Binding directly to 0.0.0.0 is sometimes necessary, but it should be a deliberate decision backed by firewall rules.

Check active listening ports:

sudo ss -lntp

If you use UFW, allow only the ports that must be reachable:

sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose

Do not expose a development Node.js port such as 3000 to the internet unless there is a specific reason. Put a reverse proxy in front of the application, enable TLS, set sensible timeouts, and restrict access at the firewall level.

For an application bound only to localhost:

server.listen(3000, '127.0.0.1');

This is safer by default. The reverse proxy can then connect locally without exposing Node.js directly to external traffic.

Keep Node.js and Dependencies Updated

Operating-system updates and application dependency updates are separate concerns. A patched Node.js runtime does not automatically remediate a vulnerable package inside node_modules.

Update system packages:

sudo apt update
sudo apt upgrade -y

For NVM installations, update the runtime separately:

nvm install --lts
nvm alias default lts/*
nvm use --lts

For application dependencies, review changes before deploying:

npm outdated
npm audit
npm audit fix

Be cautious with npm audit fix. It can update transitive dependencies and occasionally introduce breaking changes. In a production repository, run the test suite, review the lockfile diff, and deploy through staging first.

A practical release routine looks like this:

git pull
npm ci
npm run build
npm test
sudo systemctl restart myapp.service

For a high-traffic service, add a health check before switching traffic:

curl -fsS http://127.0.0.1:3000/health

If the health endpoint fails, roll back rather than leaving a broken release running behind the load balancer.

Troubleshooting Common Node.js Issues

command not found: node

This usually means Node.js is not installed, the shell has not reloaded its PATH, or multiple installations are competing.

Check what the shell resolves:

which node
type -a node
echo "$PATH"

If NVM was just installed, reload the shell:

source ~/.bashrc

If NodeSource was installed but the command is still missing, confirm that the package is present:

dpkg -l | grep nodejs
apt policy nodejs

EACCES: permission denied

This error commonly appears when npm is run with sudo, or when a directory is owned by the wrong user.

Do not routinely run:

sudo npm install

Instead, ensure the application directory belongs to the service user:

sudo chown -R myapp:myapp /opt/myapp
sudo -u myapp npm ci --omit=dev

For a development machine, avoid changing npm’s global prefix to a system directory. Prefer NVM for user-level global packages, or use a project-local installation whenever possible.

EADDRINUSE: address already in use

Another process is already listening on the port.

Find it:

sudo ss -lntp | grep :3000

Kill the specific process only after confirming what it is:

sudo kill <PID>

Avoid blindly using kill -9. First determine whether the process is an old application instance, a test server, or another critical service.

Native Module Build Failures

Packages such as bcrypt, sharp, sqlite3, and some database drivers may include native code. They require a compiler toolchain and matching headers.

Install the build tools:

sudo apt install -y build-essential python3

Then reinstall dependencies cleanly:

rm -rf node_modules package-lock.json
npm install

Only delete package-lock.json when you intentionally want to re-resolve dependencies. In normal operations, retain it; it is the record that makes installs reproducible.

NodeSource Repository Errors

If apt update fails after adding NodeSource, inspect the repository definition and key:

cat /etc/apt/sources.list.d/nodesource.list
sudo apt update

Look for:

  • An incorrect Ubuntu codename.
  • A missing or malformed GPG key.
  • Network or proxy restrictions.
  • Conflicting Node.js packages from another source.

Remove a conflicting Ubuntu npm package only after checking what depends on it:

apt policy nodejs npm
sudo apt remove nodejs npm
sudo apt update
sudo apt install -y nodejs

Review the proposed transaction carefully. On a server, an unexpected package removal is a warning sign, not something to accept automatically.

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.

Related Posts