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

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

Overview

When attempting to install Node.js version 18 on Ubuntu, some users encounter a situation where the system installs Node.js v12 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_18.x | sudo -E bash -
      sudo apt-get install -y nodejs

and then check the installed version:

      node -v

You see: v12.x.x instead of the expected v18.x.x.


Possible Causes

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 setup_12.x and setup_18.x repositories can cause the package manager to select the older version.
Ubuntu Default Repository The official Ubuntu repo includes Node.js 12 by default. If NodeSource is not configured correctly, apt falls back to Ubuntu’s own package — which is version 12.
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.

Resolution Steps

Step 1 — Verify the Installed Version

Check the current Node.js version:

      node -v

If it shows v12.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 18 Repository

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

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

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

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

Step 4 — Install Node.js 18

Now install Node.js:

      sudo apt-get install -y nodejs

Then verify:

      node -v
      npm -v

Expected output:

      v18.x.x
      8.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 18
      nvm use 18

Then confirm:

      node -v

Verification Checklist

Check Command Expected Result
Repository file cat /etc/apt/sources.list.d/nodesource.list Should show deb.nodesource.com/node_18.x
Node version node -v Should show version 18.x
APT source priority apt-cache policy nodejs Top priority should be deb.nodesource.com

    • Related Articles

    • How To Manually Install Cloudmon On Ubuntu 24.

      Overview Cloudmon officially supports Ubuntu 22. When deploying on Ubuntu 24, manual installation of the Collector and Probe packages is required. Step 1: Download the Latest Collector and Probe Packages Open the following URL in your browser: ...
    • What is the estimated installation time for Cloudmon Controller from start to finish?

      Assuming the prerequisites are satisfied and there is a stable internet connection, the installation of Cloudmon usually takes around 3 to 5 minutes.
    • Controller Installation

      Installation and Deployment Controller Installation The Cloudmon Controller is the central server that hosts the monitoring platform, stores all collected data, and provides the web interface for IT teams. Installation packages and guided setup ...
    • Probe Installation

      Installation and Deployment Probe Installation Cloudmon Probes are installed at network locations where agentless monitoring of local devices is required. Probe installation is performed directly from the Cloudmon Controller's built-in help guide. ...
    • Agent Installation

      Agents Agent Installation Install the Cloudmon agent on any device you want to monitor. Supported on Windows, Linux, macOS, and Android. Once installed, the agent is automatically discovered by the Cloudmon controller. Overview The Cloudmon agent ...