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.
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.
| Category | Root Cause | Explanation |
|---|---|---|
| Old Repository Cache | The 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 Repositories | Multiple 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 Repository | The 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 Interference | Corporate 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 Execution | The 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. |
Check the current Node.js version:
node -v
If it does NOT show v24.x, proceed with cleanup.
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
Re-add the NodeSource setup for Node.js 24:
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
🔹 Tip: Use
--retry 3for unstable network environments:
curl --retry 3 -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
Now install Node.js:
sudo apt-get install -y nodejs
Then verify:
node -v
npm -v
Expected output:
v24.x.x
10.x.x
To prevent downgrades in future updates:
sudo apt-mark hold nodejs
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
| Check | Command | Expected Result |
|---|---|---|
| Repository file | cat /etc/apt/sources.list.d/nodesource.list | Should show deb.nodesource.com/node_24.x |
| Node version | node -v | Should show version 24.x |
| APT source priority | apt-cache policy nodejs | Top priority should be deb.nodesource.com |