Installing Node.js and npm on Debian
Node.js 10 and 12 have been out of support for years. Here is how to install the current LTS release together with npm on Debian, using NodeSource with the signing key in /etc/apt/keyrings.
Node.js is the runtime behind countless web applications, APIs and Discord bots. On your own server you can install it in a few minutes. In this guide you set up Node.js together with npm on Debian 13, Debian 12 and Debian 11. The same commands work on Ubuntu.
Picking the right version matters. The older guides for Node.js 10 and Node.js 12 are out of date: neither version has received security updates for years, and neither belongs on a server today.
Which Node.js version should you install?
Node.js gets a new major version twice a year. Only the even version numbers become an LTS line (Long Term Support) and are then maintained for roughly three years. Odd versions are short-lived development lines and are not meant for production systems.
- Node.js 24 LTS ("Krypton"): the current recommendation for new projects and production servers.
- Node.js 22 LTS: still widely used, a sensible choice when an application explicitly asks for this version.
- Node.js 10 and 12: out of support since 2021 and 2022 respectively. Do not use them any more.
If in doubt, check what your application states. Many projects record the required version in the "engines" field of their package.json file.
Requirements
- Root access to your VPS or root server over SSH.
- A current Debian. Bring the system up to date first:
apt update && apt upgrade -y
To pull in the package repository you also need a few standard tools:
apt install -y ca-certificates curl gnupg
Option 1: Node.js from the Debian repositories
The simplest route goes through the repositories that ship with the system:
apt install nodejs npm -y
The upside: updates arrive automatically together with the rest of your system updates. The downside: the Debian packages usually trail the current LTS line by one or two major versions. To see which version is available on your machine before you install, run:
apt-cache policy nodejs
As of July 2026 the repositories provide: Debian 13 "Trixie" Node.js 20.19, Debian 12 "Bookworm" Node.js 18.20, Ubuntu 24.04 Node.js 18.19, Ubuntu 22.04 Node.js 12.22. If that is enough for you, you are done here. If you need a current LTS line, take option 2.
Option 2: installing Node.js 24 LTS from NodeSource
NodeSource provides official package repositories for Debian and Ubuntu. That gives you exactly the major version you want, and you still receive updates through apt.
Adding the signing key
The old route via apt-key is gone. Since Debian 11, signing keys belong in a dedicated directory under /etc/apt/keyrings/:
mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
Adding the repository and installing
Next, add the package repository. The variable sets the major version you want, in this case 24:
NODE_MAJOR=24
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
For Node.js 22, set NODE_MAJOR=22 instead. Then comes the installation itself:
apt update
apt install nodejs -y
npm is already part of the NodeSource package. Do not install the Debian package "npm" on top of it here, otherwise you end up with a package conflict.
The short route with the setup script
NodeSource also offers a script that rolls the two steps above into one:
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install nodejs -y
Convenient, but you are running a script downloaded from the internet with root privileges. On production servers, the route via key and package repository is the cleaner choice.
Checking the installation
Finally, ask both tools for their version:
node --version
npm --version
If node prints output that starts with v22. and npm returns a version number, the installation worked.
If you want to use yarn or pnpm: both can be switched on through Corepack, which is part of Node.js, so a separate installation is not needed:
corepack enable
Running several Node.js versions side by side
If you run several applications with different requirements on one server, the Node Version Manager (nvm) helps. It installs Node.js inside the user's home directory, so several versions can live next to each other and you can switch per project.
Once nvm is installed (follow the instructions in the official project for that step), these commands are all you need:
nvm install 24
nvm use 24
nvm alias default 24
Important: nvm always belongs to a single user. System services that run as a different user will not find this Node.js installation. For services, the package installation is the more reliable route.
Moving to a newer version
When a move to a new LTS line comes up later, simply change the version number in the package repository and update:
NODE_MAJOR=24
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
apt update && apt install nodejs -y
Test your application after a version jump. Interfaces can change between two major versions, and older native modules may have to be rebuilt.
Common errors
- "E: Unable to locate package nodejs":
apt updatewas forgotten after adding the package repository. - Package conflict between nodejs and npm: You installed the Debian package "npm" alongside the NodeSource package. Remove npm with
apt remove npm, because Node.js brings the matching version along itself. - "NO_PUBKEY" or "signatures couldn't be verified": The signing key is not stored under
/etc/apt/keyrings/, or the line in the package repository carries no matchingsigned-byreference. - An old version is still shown: Leftovers from an earlier installation are still on the system. Delete old files under
/etc/apt/sources.list.d/that point to nodesource, then install again. - An npm package fails while compiling: The build tools for native modules are missing. Install them with
apt install -y build-essential python3.
Frequently asked questions
Which Node.js version should I install?
Why is the version in the Debian repository so old?
Do I have to install npm separately?
How do I move to a newer version later on?
Why does the signing key live in /etc/apt/keyrings?
2022-2026 KernelHost GmbH. All rights reserved. This guide is protected by copyright. Republishing it on other websites, in whole, in part or in edited form, is not permitted without our written consent. Quoting with a source credit and a link is expressly welcome.

