Node.js Upgrade Guide for Ubuntu | Generated by AI

Home 2025.08

Upgrading Node.js on Ubuntu can be done in several ways. The most reliable and recommended methods are using nvm (Node Version Manager) or the NodeSource repository. Below are step-by-step instructions for both methods.


NVM allows you to install and manage multiple Node.js versions easily.

1. Install NVM

Open a terminal and run:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Then, reload your shell:

source ~/.bashrc

or

source ~/.zshrc

(depending on your shell)

2. Install the Latest Node.js Version

List available versions:

nvm ls-remote

Install the latest LTS version (recommended for most users):

nvm install --lts

Or install a specific version (e.g., 20.x):

nvm install 20

3. Set Default Version

nvm alias default 20

4. Verify

node -v
npm -v

Method 2: Using NodeSource Repository

This method installs Node.js system-wide.

1. Remove Old Node.js (if installed via apt)

sudo apt remove --purge nodejs npm
sudo apt autoremove

2. Add NodeSource Repository

For Node.js 20.x (LTS as of August 2025):

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

For Node.js 22.x (if available):

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

3. Install Node.js

sudo apt install -y nodejs

4. Verify

node -v
npm -v

Ubuntu’s default repository often contains outdated Node.js versions. If you still want to use it:

sudo apt update
sudo apt install nodejs npm

But this is not recommended for development, as the version is usually old.


Which Method Should You Use?


Back Donate