Install latest Node.js on Ubuntu 24.04 with PPA-style APT packages and finish with both node and npm working in about ten minutes. This guide uses NodeSource’s current-release repository, verifies the installed runtime, and runs a private HTTP test without exposing an application port.
Prerequisites
- A fresh 64-bit Ubuntu 24.04 LTS server with at least 1 GB of RAM and 2 GB of free disk space for Node.js, npm, and a small project.
- SSH access as
root, or a normal user with workingsudoprivileges and permission to install APT packages. - Outbound HTTPS access to
deb.nodesource.comand Ubuntu package mirrors. No domain name is needed for the local verification test. - A VPSLake Linux VPS if you need a root-access Ubuntu server for Node.js applications.
The commands use sudo. If you are logged in as root, remove sudo from each command. NodeSource’s setup_current.x selector follows the current Node.js major release; at the time of writing, that is the Node.js 26 line. Use the LTS selector described in the FAQ if your application prioritizes long-term maintenance over the newest features.
Step 1: Confirm Ubuntu 24.04 and prepare APT
Checking the release and CPU architecture first prevents you from adding a repository intended for a different system.
. /etc/os-release && printf 'ID=%s\nVERSION_ID=%s\nVERSION_CODENAME=%s\n' "$ID" "$VERSION_ID" "$VERSION_CODENAME"
dpkg --print-architecture
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
The first checks should identify Ubuntu Noble and an architecture supported by NodeSource, normally amd64 or arm64:
ID=ubuntu
VERSION_ID="24.04"
VERSION_CODENAME=noble
amd64
If the release is not 24.04 or the architecture is not amd64/arm64, stop and use instructions for that operating system or architecture. Do not force Noble repository metadata onto another Ubuntu release.
Step 2: Add the NodeSource current-release repository
The setup script installs the repository key and a signed APT source file, so APT can receive current Node.js packages without the deprecated apt-key workflow.
Download the script first, then execute the local copy with sudo:
curl -fsSL https://deb.nodesource.com/setup_current.x -o /tmp/nodesource_setup.sh
sudo -E bash /tmp/nodesource_setup.sh
rm -f /tmp/nodesource_setup.sh
The output should end with a successful repository message and an instruction to install nodejs. The script currently maps setup_current.x to the Node.js 26 repository and uses the nodistro suite, which is normal for this NodeSource feed. NodeSource lists Ubuntu 24.04 Noble as a supported Debian-based target in its distribution instructions.
Confirm that APT sees a candidate before installing it:
apt-cache policy nodejs | sed -n '1,8p'
Expected output resembles this; the exact patch number changes as Node.js releases updates:
nodejs:
Installed: (none)
Candidate: 26.x.y-1nodesource1
Version table:
*** 26.x.y-1nodesource1 600
600 https://deb.nodesource.com/node_26.x nodistro/main amd64 Packages
Step 3: Install Node.js and npm
The nodejs package from NodeSource includes the Node.js runtime and npm, so one APT installation gives you the tools needed to run and install JavaScript applications.
sudo apt-get install -y nodejs
node --version
npm --version
command -v node
command -v npm
The version numbers will vary, but the result should show a v26 Node.js release, a numeric npm version, and binaries under /usr/bin:
v26.x.y
10.x.y
/usr/bin/node
/usr/bin/npm
If you had an older Node.js installation from Ubuntu, APT may replace it when the NodeSource candidate has the higher priority. Check the selected origin with apt-cache policy nodejs before proceeding.
Step 4: Run a private Node.js HTTP test
A loopback-only server proves that Node.js can execute JavaScript and accept an HTTP request while keeping port 3000 inaccessible from the public network.
Run this temporary test in one Bash session:
node -e 'require("node:http").createServer((request, response) => response.end("Node.js is working on Ubuntu 24.04\\n")).listen(3000, "127.0.0.1")' >/tmp/node-check.log 2>&1 &
NODE_PID=$!
sleep 1
curl -fsS http://127.0.0.1:3000
kill "$NODE_PID"
wait "$NODE_PID" 2>/dev/null || true
The curl request should return:
Node.js is working on Ubuntu 24.04
The process listens only on 127.0.0.1, and the final kill removes it. For a real application, put the service behind a TLS-enabled reverse proxy and open only the required web ports in UFW; do not expose a development listener just to test it.
Verify the Node.js installation
These checks confirm the major release, npm availability, the active APT source, and the runtime’s ability to load a built-in module:
node --version
npm --version
node -p 'process.platform + " " + process.arch'
node -e 'console.log(require("node:fs").existsSync("/etc/os-release") ? "Node.js runtime check passed" : "Runtime check failed")'
apt-cache policy nodejs | sed -n '1,7p'
Expect a v26 version, a numeric npm version, linux amd64 or linux arm64, a passed runtime message, and a NodeSource candidate in the policy output. For runtime APIs and supported behavior, use the official Node.js API documentation.
Troubleshooting
apt-cache policy nodejs still shows Ubuntu’s old version
The setup script may not have completed, or APT may still have stale package metadata. Confirm that the source file exists, refresh APT, and inspect the candidate again:
sudo test -f /etc/apt/sources.list.d/nodesource.sources && echo "NodeSource source file found"
sudo apt-get update
apt-cache policy nodejs
The policy output should include https://deb.nodesource.com/node_26.x. If it does not, rerun Step 2 and read the first error from the setup script instead of installing the Ubuntu package by accident.
Could not resolve host: deb.nodesource.com
This is a DNS or outbound-network problem, not a Node.js package problem. Check the resolver and HTTPS path, then correct the VPS network settings or provider firewall before repeating the download:
getent hosts deb.nodesource.com
curl -I https://deb.nodesource.com
Do not replace the repository URL with an untrusted mirror. A working result returns an address from getent and an HTTPS response header from curl.
Could not get lock /var/lib/dpkg/lock-frontend
Another APT process, commonly unattended upgrades, is using the package database. Wait for that operation to finish, then retry; never delete the lock file while apt or dpkg is active.
ps -ef | grep -E '[a]pt|[d]pkg|unattended'
sudo dpkg --configure -a
sudo apt-get install -y nodejs
If dpkg --configure -a reports an active package process, wait and run it again after the process exits.
npm ERR! EACCES during a global install
The system Node.js installation is owned by APT, so a normal user should not write packages into its protected global directory. Prefer project-local dependencies:
mkdir -p ~/YOUR_APP
cd ~/YOUR_APP
npm init -y
npm install YOUR_PACKAGE
Replace YOUR_APP with your application directory and YOUR_PACKAGE with the dependency name you actually need. The resulting package.json and lockfile remain owned by your user, which avoids turning the system installation into a shared writable directory.
Use sudo npm install -g only for a package you deliberately want system-wide, and review its publisher and permissions first. Avoid making /usr or npm’s global directories writable by every user.
Hardening and next steps
- Keep the Node.js package on the current branch with
sudo apt-get update && sudo apt-get upgrade, and test application dependencies before accepting major updates. - Run production applications under a dedicated non-root account and a systemd service; never run an internet-facing app as
rootjust because Node.js was installed withsudo. - Allow only SSH, HTTP, and HTTPS as needed in UFW. You can draft a narrow rule set with the VPSLake UFW firewall generator, then review every rule before applying it.
- Store secrets outside source files, commit
package-lock.json, and usenpm auditas one input to dependency review rather than blindly upgrading production packages.
FAQ
Is NodeSource a real Ubuntu PPA?
It is not a Launchpad PPA; it is a signed third-party APT repository commonly called a PPA in installation searches. The setup script creates the repository configuration and signing-key association for Node.js packages on Ubuntu.
Should I install the current release or Node.js LTS?
Choose the current release when you specifically need its newest runtime features. For most production websites and APIs, use NodeSource’s LTS selector instead by changing setup_current.x in Step 2 to setup_lts.x; that tracks the supported long-term-maintenance branch rather than the newest major.
Does the Node.js package include npm?
Yes. The NodeSource nodejs package installs npm alongside the runtime, so npm --version should work immediately after the APT installation. Project dependencies should still be installed locally inside each application directory.
How do I update Node.js later?
For updates within the selected major line, run sudo apt-get update followed by sudo apt-get upgrade. Switching from Current to LTS, or from one major line to another, is a deliberate repository change; check application compatibility and remove conflicting NodeSource source files before changing branches.