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.