On this page
- Which install method should you pick?
- What do you need before installing?
- How do you install from the NodeSource repo on Ubuntu or Debian?
- How do you install from NodeSource on Rocky Linux or AlmaLinux?
- How do dnf module streams work on Rocky and Alma 9?
- When are the plain distro packages good enough?
- How do you confirm the install really works?
- Where should global npm packages go?
- How do you keep Node.js patched and when do you build from source?
- Questions
Which install method should you pick?
Pick the NodeSource repository when you run real applications, because it tracks the official Node.js release lines and receives security updates through your normal package manager. The distro packages are older but fully supported by the distribution, and the dnf module streams on Rocky and Alma sit between the two. A per-user version manager is the right answer when one machine has to serve several projects with different runtimes; that case has its own page on running several Node.js versions with nvm.
- NodeSource repo: current LTS, system wide, updated with
aptordnf. - Distro package: Ubuntu 24.04 and Debian 12 ship Node.js 18, Debian 13 ships Node.js 20, Ubuntu 22.04 ships a much older 12.x.
- dnf module streams: Rocky and Alma 9 publish several streams in AppStream, switchable with one command.
- Build from source: only for unusual flags or architectures, covered at the end.
Node.js publishes a new even-numbered major every spring, and that line becomes Long Term Support in October. Production servers should stay on an LTS line; odd-numbered releases are short lived.
What do you need before installing?
You need a server you can reach over SSH and a normal user with sudo rights. If this is a fresh instance, work through the first SSH session and create the deploy user first. Node itself is light: a 1 GB instance runs a small API comfortably, but npm installs of large front-end projects and native module builds can spike memory well above that, so add a swap file on small plans or pick 2 GB from the start.
Update the package index and install the helpers the setup scripts expect.
# Ubuntu and Debian
sudo apt update
sudo apt install -y ca-certificates curl gnupg
# Rocky Linux and AlmaLinux 9
sudo dnf install -y curl ca-certificatesHow do you install from the NodeSource repo on Ubuntu or Debian?
Download the setup script for the release line you want, read it if you like, then run it with sudo. The script adds a signed apt source under /etc/apt/sources.list.d and a key under /usr/share/keyrings. After that a plain apt install nodejs pulls the NodeSource build.
curl -fsSL https://deb.nodesource.com/setup_lts.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejsThe setup_lts.x script always points at the line that is LTS on the day you run it. If you prefer to pin a major so that a future LTS does not arrive by surprise, use a numbered script instead, for example setup_24.x. The pinned source keeps you on the 24 line and still delivers its patch releases.
Do not install the separate npm package from the distro afterwards. The NodeSource package bundles npm and corepack, and mixing in the Ubuntu npm package causes file conflicts.
How do you install from NodeSource on Rocky Linux or AlmaLinux?
The RPM flavour works the same way: one script, then one dnf command. It writes a repo file to /etc/yum.repos.d and imports the signing key.
curl -fsSL https://rpm.nodesource.com/setup_lts.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo dnf install -y nodejsIf dnf complains that the package is filtered by modular filtering, an AppStream module stream is already enabled. Reset it with sudo dnf module reset nodejs and run the install again so the NodeSource repo wins.
How do dnf module streams work on Rocky and Alma 9?
Module streams let you choose a Node.js major from the distribution itself, with no third-party repo. List what your point release offers, enable one stream, then install it.
dnf module list nodejs
sudo dnf module enable -y nodejs:22
sudo dnf install -y nodejs npmThe listing shows which streams exist and which one is the default. To move to another stream later, reset first, then enable the new one and sync packages:
sudo dnf module reset -y nodejs
sudo dnf module enable -y nodejs:24
sudo dnf distro-sync -yIf nodejs:24 is not in your list yet, your point release does not carry it; stay on the newest listed stream or use NodeSource. Streams receive security fixes from the distribution for as long as that stream is supported.
When are the plain distro packages good enough?
They are fine for command line tools, build helpers and scripts that already run on the version your release carries. On Debian 13 the stock nodejs is a 20.x release, which many tools still accept. Ubuntu 24.04 and Debian 12 carry 18.x, which is past its upstream end of life even though the distributions still patch it, so new frameworks may refuse to start.
sudo apt install -y nodejs npm
node -vCheck the version against the engines field in your project package.json before you rely on it.
How do you confirm the install really works?
Print the versions, then start a tiny server and query it. This proves the binary runs, npm resolves, and the network stack answers.
node -v
npm -v
node -e "require('http').createServer((q,s)=>s.end('ok\n')).listen(3000,'127.0.0.1')" &
curl http://127.0.0.1:3000
kill %1You should see a version starting with the major you chose and the word ok from curl. Leave application ports bound to 127.0.0.1 and put a web server in front, as shown in an Express app behind Nginx. If you do need a port reachable from outside for a test, open it in the OS firewall, since filtering on BitcoinVPS is done inside the instance:
# Ubuntu and Debian
sudo ufw allow 3000/tcp
# Rocky and Alma
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reloadRemove the rule when the test is finished.
Where should global npm packages go?
With a system-wide install, global packages land in /usr/lib/node_modules (or /usr/local/lib on some builds) and need sudo. That is acceptable for a few tools such as PM2. To avoid sudo for everything else, give your user its own prefix:
mkdir -p ~/.npm-global
npm config set prefix ~/.npm-global
echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcCorepack ships with the NodeSource builds of current lines and can activate Yarn or pnpm per project with corepack enable. Newer Node.js majors are phasing corepack out of the default bundle, so if the command is missing, install it with npm install -g corepack.
How do you keep Node.js patched and when do you build from source?
Updates arrive with the rest of the system. A routine sudo apt upgrade or sudo dnf upgrade installs new patch releases of the line you chose; restart your Node processes afterwards so they load the new binary. Jumping to a new major is a separate project, explained in upgrading Node.js safely.
Compiling from source is rarely needed. Do it only when you need a custom configure flag or are testing an unreleased branch. It takes a C++ toolchain, Python 3 and a long build, and a 2 vCPU instance needs a good while to finish:
sudo apt install -y build-essential python3 git
git clone --depth 1 --branch v24.11.1 https://github.com/nodejs/node.git
cd node
./configure --prefix=/opt/node-24
make -j"$(nproc)"
sudo make installPick the tag of the current patch release from the project release list. A source build gets no automatic updates, so you own every security patch afterwards.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Install Node.js and npm
Does installing nodejs also install npm?
Yes for the NodeSource package: npm is bundled inside nodejs. On Ubuntu, Debian and the dnf streams, npm is a separate package, so install npm along with nodejs.
Which Node.js version should a new project use?
Use the newest line that is marked LTS on the Node.js release schedule. It receives bug and security fixes for about thirty months, which covers the life of most deployments.
Why does node -v still show the old version after I added NodeSource?
The distro package is still installed or pinned. Run apt policy nodejs to see which source wins, remove the old package with sudo apt remove nodejs npm, then install again. On Rocky or Alma, reset the module stream first.
Can I install Node.js on FreeBSD 14 the same way?
No. FreeBSD uses packages such as node22 or node24 from pkg, for example pkg install node24 npm-node24. The steps on this page cover Linux images only.
How much memory does Node.js need?
A small idle API uses well under 100 MB. Large npm installs and front-end builds can need 1 to 2 GB for a short time, so add swap on a 1 GB plan or pick a 2 GB instance.
Is it safe to pipe the setup script straight into bash?
It works, but downloading the script to a file first lets you read what it changes before running it with sudo. The commands on this page use that two-step form.