Skip to content
Runbook

Install Node.js on Ubuntu / Debian

Server-side JavaScript runtime, built on the V8 engine, shipped with the npm package manager.

Runtimejavascriptruntimebackendv8npm

Installation

NodeSource repository (LTS) · apt
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

The "nodejs" package in the default Ubuntu/Debian repository is often old; NodeSource provides the up-to-date LTS with npm.

Verify the installation

Verify
node --version

Important files

TypePathDescription
config~/.npmrcUser configuration for npm (registry, proxy, authentication tokens).
binary/usr/bin/nodeRuntime executable installed by the NodeSource package.

Command-line tools

  • nodeThe JavaScript runtime.
  • npmNode.js package manager.
  • npxRuns a package binary without installing it globally.
  • corepackEnables and manages pnpm and yarn. Still present with Node 24 (LTS), but removed from the package starting with Node 25.

Uninstall

Uninstall
sudo apt-get purge -y nodejs
sudo rm -f /etc/apt/sources.list.d/nodesource.sources /usr/share/keyrings/nodesource.gpg /etc/apt/preferences.d/nodejs /etc/apt/preferences.d/nsolid
sudo apt-get update

Good to know

  • The default APT repository provides a version of Node.js that is often several cycles behind; prefer NodeSource or a version manager (nvm/fnm).
  • Enable pnpm and yarn via Corepack with "corepack enable"; Corepack still ships with Node 24, but it is removed starting with Node 25 and must then be installed separately.
  • The setup_lts.x script configures the NodeSource APT repository and its GPG key.

Installation on Ubuntu / Debian

The nodejs package found in the default repositories of Ubuntu and Debian is generally very old and unsuitable for modern use. The recommended method is the official NodeSource repository: the setup_lts.x script adds the APT repository and its key, then apt-get install -y nodejs installs the latest LTS, npm included. To pin a specific major version, replace setup_lts.x with, for example, setup_22.x.

Alternative: version manager

For development environments where several versions coexist, nvm or fnm are preferable to a system installation. They install Node.js in your user directory, avoiding sudo for global packages and making it easy to switch from one version to another per project via a .nvmrc file.

Locations and configuration

With NodeSource, the executable is located in /usr/bin/node. The user configuration for npm is in ~/.npmrc. Enable pnpm and yarn without any additional installation thanks to corepack enable.