How to Install Latest Node.js on Ubuntu 22.04 (Step-by-Step)

Install latest Node.js on Ubuntu 22.04 with PPA-style APT packages, verify npm, run a local test server, and fix common setup errors quickly.
A polished 3D illustration of a glowing Node.js runtime cube above a Linux server with cyan light trails on a midnight-blue background.

Install latest Node.js on Ubuntu 22.04 with PPA-style APT packages and have node and npm ready in about ten minutes. You will add NodeSource’s signed repository, install the current Node.js release, and run a loopback-only HTTP test without opening a public application port.

Prerequisites

  • A 64-bit Ubuntu 22.04 LTS server with at least 1 GB of RAM and 2 GB of free disk space for Node.js, npm, and a small application.
  • SSH access as root, or a normal account with working sudo privileges.
  • Outbound HTTPS access to Ubuntu package mirrors and deb.nodesource.com.
  • No domain is required for this installation or its local verification test.
  • A VPSLake Linux VPS if you need a root-access Ubuntu server for Node.js workloads.

The commands use sudo. If you are already logged in as root, remove sudo from the commands. This guide follows NodeSource’s current-release selector, which installs the newest Node.js major available from that repository; the exact patch version will change over time.

Step 1: Confirm Ubuntu 22.04 and prepare APT

Checking the release and architecture before changing APT helps prevent installing packages intended for another Ubuntu version.

. /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 release check should identify Ubuntu Jammy and a supported 64-bit architecture:

ID=ubuntu
VERSION_ID="22.04"
VERSION_CODENAME=jammy
amd64

NodeSource also supports arm64 packages. If the output is not Ubuntu 22.04, stop here and use instructions for the release shown by /etc/os-release; do not point a Jammy system at a different distribution’s repository.

Step 2: Add the NodeSource current-release repository

NodeSource provides a signed APT repository rather than a Launchpad PPA, and its setup script creates the keyring and source configuration needed by Ubuntu 22.04.

Download the official script to a temporary file so you can see and rerun the exact local file that configures APT:

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 setup output should finish by telling you to install nodejs. It currently selects the Node.js 26 repository; the selector is useful here because it follows the current release instead of leaving the server on the older Node.js 20 branch from many older tutorials. The official NodeSource Debian and Ubuntu instructions document the supported architectures and setup process.

Check that APT has a NodeSource candidate before installing anything:

apt-cache policy nodejs | sed -n '1,9p'

You should see a candidate from deb.nodesource.com, with a version and major line that may be newer than this example:

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

The nodistro suite in this output is normal for the current NodeSource feed. The important checks are the deb.nodesource.com origin and a non-empty candidate.

Step 3: Install Node.js and npm

The NodeSource nodejs package includes the runtime and npm, so one package installation provides both the JavaScript interpreter and the package manager.

sudo apt-get install -y nodejs
node --version
npm --version
command -v node
command -v npm

The major version should match the current repository branch, while the npm version and patch number can change independently:

v26.x.y
11.x.y
/usr/bin/node
/usr/bin/npm

If Ubuntu already had an older nodejs package, APT should choose the NodeSource candidate because the setup script adds the repository preference. Use apt-cache policy nodejs to confirm the selected origin if the installed major version is unexpected.

Step 4: Run a private Node.js HTTP test

This temporary server checks that Node.js can load its built-in HTTP module and answer a request while binding only to localhost.

Run the complete test in one SSH session:

node -e 'require("node:http").createServer((request, response) => response.end("Node.js is working on Ubuntu 22.04\\n")).listen(3000, "127.0.0.1")' >/tmp/node-test.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 request should return this line:

Node.js is working on Ubuntu 22.04

The process is killed at the end and port 3000 is never bound to the public network interface. For a real web application, use a dedicated service account and a TLS-enabled reverse proxy, then open only the public ports the application actually needs.

Verify the Node.js installation

Run these checks after the test to confirm the runtime, npm, architecture, and a built-in module all work from your shell:

node --version
npm --version
node -p 'process.platform + " " + process.arch'
node -e 'console.log(typeof require("node:fs").readFileSync === "function" ? "Built-in module check passed" : "Built-in module check failed")'
apt-cache policy nodejs | sed -n '1,7p'

Expected output includes a v26 release, a numeric npm version, linux amd64 or linux arm64, a passed module check, and a NodeSource candidate. For runtime APIs and supported behavior, see the official Node.js API documentation.

Troubleshooting

APT shows Ubuntu’s old Node.js version

The setup script may not have finished, or the package lists may be stale. Check the source file, 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 contain https://deb.nodesource.com/node_26.x. If it does not, rerun Step 2 and read the first error printed by the setup script before installing the Ubuntu archive version.

Could not resolve host: deb.nodesource.com

The VPS cannot resolve the repository hostname or cannot reach it over HTTPS. Test DNS and the outbound connection separately:

getent hosts deb.nodesource.com
curl -I https://deb.nodesource.com

An address from getent and an HTTPS response header indicate that the path is available. If either command fails, fix the server’s resolver, network route, or provider-level egress restriction and then repeat Step 2.

Could not get lock /var/lib/dpkg/lock-frontend

Another package operation, often Ubuntu’s unattended upgrades, is using the APT database. Wait for it to finish instead of deleting the lock file, then repair any interrupted package configuration:

ps -ef | grep -E '[a]pt|[d]pkg|unattended'
sudo dpkg --configure -a
sudo apt-get install -y nodejs

If the process list still shows an active package operation, wait and run the repair after it exits.

npm ERR! EACCES during a global install

APT owns the system Node.js directories, so a normal user cannot write arbitrary global packages there. Install application dependencies locally inside the project instead:

mkdir -p ~/YOUR_APP
cd ~/YOUR_APP
npm init -y
npm install YOUR_PACKAGE

Replace YOUR_APP with the application directory and YOUR_PACKAGE with the dependency you need. This keeps the package files owned by your account and avoids making system directories writable. Use sudo npm install -g only when you intentionally need a system-wide command and have reviewed the package.

Hardening and next steps

  • Run production applications under a dedicated non-root account and a systemd service; Node.js does not need root privileges to serve an application on a high port.
  • Keep the server patched with sudo apt-get update && sudo apt-get upgrade, and test application compatibility before accepting a new major Node.js release.
  • If the application will be public, allow only SSH, HTTP, and HTTPS in UFW. The VPSLake UFW firewall generator can help draft a narrow ruleset for review before you apply it.
  • Keep package-lock.json in version control, store secrets outside the repository, and review npm audit results before changing production dependencies.

FAQ

Is NodeSource a real Ubuntu PPA?

No. Search results often call it a PPA, but NodeSource is a signed third-party APT repository rather than a Launchpad-hosted PPA. The setup script adds its keyring and source file so Ubuntu can verify the packages through APT.

Should I use the current release or Node.js LTS?

Use the current release when you need the newest runtime features and your dependencies support that major version. For most production services, the LTS line is the safer default; replace setup_current.x with setup_lts.x in Step 2 before running the script.

Does installing nodejs also install npm?

Yes. The NodeSource package installs npm with the Node.js runtime, which is why npm --version works immediately after Step 3. Keep each application’s dependencies local instead of installing them globally into the APT-managed directory.

How do I update Node.js later?

For updates within the selected major line, run sudo apt-get update and then sudo apt-get upgrade. Moving between Current and LTS is a repository choice, so check your application’s supported Node.js versions before changing the selector.

Samrat Ghosh
Written by

Samrat Ghosh

Founder & Infrastructure Engineer

Samrat Ghosh is the founder of VPSLake, where he builds and runs the remote desktop and VPS hosting infrastructure the company is built on. He writes hands-on guides about RDP, Windows Server, VPS management and secure remote access - the practical documentation he wishes had…

Previous Article

How to Install Latest Node.js on Ubuntu 24.04 with PPA

Next Article

Tailscale Exit Node VPS: Set Up a Fixed US IP

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨