Resolving Node.js 24 Installation Installs Node.js 12 on Ubuntu

Resolving Node.js 24 Installation Installs Node.js 12 on Ubuntu

Overview

When attempting to install Node.js version 24 on Ubuntu, some users encounter a situation where the system installs an older Node.js version instead.
This typically happens due to outdated repositories, cached package sources, or incorrect repository configurations that still point to older Node.js sources.

This article explains the root causes, symptoms, and step-by-step resolution methods to ensure the correct version of Node.js is installed.


Issue Description

Symptom:
When you run:

      curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
      sudo apt-get install -y nodejs

and then check the installed version:

      node -v

You see: an older version (e.g., v12.x.x, v18.x.x, or v20.x.x) instead of the expected v24.x.x.


Possible Causes

CategoryRoot CauseExplanation
Old Repository CacheThe system's package list still references older Node.js repositories or cached metadata.Ubuntu's APT sometimes retains older metadata, causing apt to fetch packages from outdated sources.
Duplicate Node.js RepositoriesMultiple NodeSource entries exist in /etc/apt/sources.list.d/.Having both older and newer repository entries can cause the package manager to select the older version.
Ubuntu Default RepositoryThe official Ubuntu repo often includes an older LTS version of Node.js by default.If NodeSource is not configured correctly, apt falls back to Ubuntu's own package — which may be several versions behind.
Proxy or Mirror InterferenceCorporate proxies or mirrors caching old packages.Cached responses from an internal mirror or proxy may serve outdated Node.js binaries.
Broken or Incomplete Setup Script ExecutionThe NodeSource setup script did not complete due to a "broken pipe" or partial download.If the script didn't update APT sources correctly, the system reverts to the older repo.

Resolution Steps

Step 1 — Verify the Installed Version

Check the current Node.js version:

      node -v

If it does NOT show v24.x, proceed with cleanup.


Step 2 — Remove Existing Node.js and Old Repositories

Remove the existing Node.js installation and old repository entries:

      sudo apt-get remove -y nodejs
      sudo rm /etc/apt/sources.list.d/nodesource.list

Also clean apt cache:

      sudo apt-get clean
      sudo apt-get autoremove -y
      sudo apt-get update

Step 3 — Add the Correct Node.js 24 Repository

Re-add the NodeSource setup for Node.js 24:

      curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -

      🔹 Tip: Use --retry 3 for unstable network environments:

      curl --retry 3 -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -

Step 4 — Install Node.js 24

Now install Node.js:

      sudo apt-get install -y nodejs

Then verify:

      node -v
      npm -v

Expected output:

      v24.x.x
      10.x.x

Step 5 — Lock to the Correct Version (Optional)

To prevent downgrades in future updates:

      sudo apt-mark hold nodejs

Alternative Installation (Using NVM)

If the above steps don't work or you prefer version control flexibility, install via Node Version Manager (NVM):

      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
      source ~/.bashrc
      nvm install 24
      nvm use 24

Then confirm:

      node -v

Verification Checklist

CheckCommandExpected Result
Repository filecat /etc/apt/sources.list.d/nodesource.listShould show deb.nodesource.com/node_24.x
Node versionnode -vShould show version 24.x
APT source priorityapt-cache policy nodejsTop priority should be deb.nodesource.com