Tutorials  /  Ubuntu

Upgrade Node.js on Ubuntu 24.04 – NVM, APT & Binary Guide

Ccentron Redaktion · September 2025 ·8 min read ·Ubuntu, Tutorial

Node.js is a free, cross-platform runtime environment that allows JavaScript to run on the server side. By installing Node.js on Ubuntu, you gain access to its powerful ecosystem, including the Node Package Manager (npm), the official registry for JavaScript packages. It is widely used in both front-end and back-end development, supported by a strong developer community and extensive documentation—making it a fundamental tool in modern application development.

This guide explains how to upgrade Node.js on Ubuntu 24.04 using three different methods: NVM (Node Version Manager), official binary distributions, and the APT package manager. It also covers how to check the installed version before and after upgrading.

VM

Try it yourself: cloud servers from €3.11/month

ccloud³ VMs from German data centers – deployed in seconds, billed by the hour, with a €200 starting credit for new accounts. Launch a server →

Prerequisites

Before you start, ensure you have the following in place:

  • An Ubuntu 24.04 server with Node.js already installed.
  • SSH access to the server.
  • A non-root user account with sudo privileges.
  • Access to the NodeSource version chart to verify supported Node.js versions for Ubuntu 24.04.

Check the Installed Node.js Version

Before upgrading, verify the version currently installed. This helps confirm if the upgrade has been applied successfully.

Console
$ node -v

Output:

v18.19.1

If you get a “command not found” error, Node.js isn’t installed. In that case, follow one of the upgrade methods below to install your required version.

Note: It’s recommended to compare your installed version with the latest LTS release listed on the official Node.js website to decide if an update is needed.

Install Node Version Manager (NVM)

Node Version Manager (NVM) is a CLI tool that allows you to install, manage, and switch between multiple Node.js versions on the same system. It makes upgrading easier and lets you define a default version for your shell sessions. Follow the steps below to set up NVM.

Only for the NVM method: You only need this section if you want to upgrade Node.js with NVM. If you plan to use binary packages or APT, skip ahead to Upgrade Node.js on Ubuntu 24.04 – installing NVM on top of those methods leads to conflicts.

Download and run the NVM installation script:

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

Important: NVM works entirely inside your own user account under ~/.nvm. Never run the installation script, nvm commands or npm install -g under NVM with sudo or from a root shell. Doing so creates root-owned directories in ~/.nvm, and later commands such as nvm alias default fail because your user can no longer write there. If this has already happened, give the files back to your user:

Console
$ sudo chown -R "$USER":"$USER" ~/.nvm

Reload your shell configuration file to activate NVM:

Console
$ source ~/.bashrc

If you use Zsh, replace the above command with:

Console
$ source ~/.zshrc

Confirm that NVM was installed correctly:

Console
$ nvm --version

Output:

0.40.2

Upgrade Node.js on Ubuntu 24.04

You can upgrade Node.js on Ubuntu 24.04 using NVM, binary packages, or the APT package manager. Choose the method that fits your setup best.

Warning: Use only one upgrade method. Mixing NVM, binary downloads, and APT may lead to conflicts. If you change your method, make sure to fully remove previously installed versions of Node.js.

Switching from NVM to binary packages or APT: As long as NVM is loaded when your shell starts, it puts its own Node.js version at the front of your PATH. A version installed via APT under /usr/bin stays hidden, and node -v keeps reporting the NVM version. Remove NVM before you switch:

Console
$ nvm unload
Console
$ rm -rf "$NVM_DIR"

Then delete the NVM lines from ~/.bashrc or ~/.zshrc (export NVM_DIR=… and the two lines that load nvm.sh and bash_completion) and open a new shell.

NVM is the preferred method as it supports installing the latest LTS or a specific version, giving developers flexibility when working with different projects.

Install the Latest LTS Version with NVM

The Long-Term Support (LTS) version is the most stable and secure release, recommended for production use. Here’s how to install and set the latest LTS version using NVM:

List all available Node.js versions:

Console
$ nvm list-remote

Output:

...

v20.12.2 (LTS: Hydrogen)

v22.14.0 (LTS: Iron)

v23.0.0

Install the most recent LTS version:

Console
$ nvm install --lts

Output:

Installing latest LTS version.

Downloading and installing node v22.14.0...

Now using node v22.14.0 (npm v10.6.0)

Set the installed version as the default for all sessions:

Console
$ nvm alias default node

Output:

default -> node (-> v22.14.0)

For production, always prefer an LTS version to ensure stability and long-term support.

Install a Specific Version with NVM

If your project depends on a particular Node.js release, you can install that version instead.

List available versions:

Console
$ nvm list-remote

Output:

...

v18.19.1 (LTS: Hydrogen)

v20.12.2 (LTS: Iron)

v22.1.0

Install a specific version by replacing <version> with the version number (e.g., 20.12.2):

Console
$ nvm install <version>

Set the installed version as the default:

Console
$ nvm alias default <version>

Note: When switching Node.js versions, global npm packages installed under the old version won’t transfer. You’ll need to reinstall them with npm install -g <package> – again without sudo.

Upgrade Node.js Using Binary Packages

The official Node.js website provides precompiled binaries for Linux systems. This method is useful if you require a specific version that is not available via package managers like APT or NVM.

Download the Node.js binary package, replacing <version> with the desired release number. You can find all available versions on the official Node.js downloads page.

Console
$ wget https://nodejs.org/dist/v<version>/node-v<version>-linux-x64.tar.xz

Extract the archive to /usr/local/ to install Node.js system-wide:

Console
$ sudo tar -C /usr/local --strip-components 1 -xJf node-v<version>-linux-x64.tar.xz

Add /usr/local/bin to the beginning of your PATH so the system prioritizes the new version:

Console
$ export PATH=/usr/local/bin:$PATH

Make the PATH modification permanent by appending it to your shell configuration file:

Console
$ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bashrc

Reload your shell configuration to apply the changes:

Console
$ source ~/.bashrc

If you use Zsh, replace ~/.bashrc with ~/.zshrc in the last two steps.

Upgrade Node.js Using APT

APT is Ubuntu’s built-in package manager. This method installs or upgrades Node.js by enabling the official NodeSource repository. It’s ideal for environments managed system-wide or automated deployments.

Download the NodeSource setup script. Replace <version> with the major version number followed by .x (e.g., 20.x or 22.x). Supported versions can be found on the NodeSource distributions page.

Console
$ curl -fsSL https://deb.nodesource.com/setup_<version> -o nodesource_setup.sh

Run the script with root privileges. It only adds the NodeSource signing key and package repository; Node.js itself is installed in the next steps. To review what the script does before running it, open it with less nodesource_setup.sh.

Console
$ sudo bash nodesource_setup.sh

Note: If your server reaches the internet through a proxy, use sudo -E bash nodesource_setup.sh so the proxy variables are preserved. Without a proxy, -E is not needed – it passes your entire user environment to root.

Update the package index:

Console
$ sudo apt update

Install Node.js:

Console
$ sudo apt install -y nodejs

Verify that npm was installed alongside Node.js:

Console
$ npm -v

Output:

10.5.0

The Node.js package from NodeSource includes npm by default, so no separate installation is required.

Verify the Active Node.js Version

After completing the upgrade, check that your system is using the correct Node.js and npm versions. This confirms that the installation method worked properly and your environment is ready for development or deployment.

Check the active Node.js version:

Console
$ node -v

Output:

v22.16.0

Check the npm version bundled with Node.js:

Console
$ npm -v

Output:

10.9.2

If the displayed versions match the ones you installed, the upgrade was successful and your environment is correctly configured.

If node -v still shows the old version after switching to APT or binary packages, NVM is most likely still active. Run which node to see which installation your shell is using: /usr/bin/node (APT), /usr/local/bin/node (binary package) or a path under ~/.nvm (NVM).

Conclusion

In this tutorial, you upgraded Node.js on Ubuntu 24.04 using one of three supported methods: NVM, binary packages, or the APT package manager. You confirmed the upgrade by checking the active Node.js and npm versions. Depending on your workflow, each method offers flexibility for development, manual control, or automated deployments. For advanced configuration, refer to the official Node.js documentation.

Claim €200 credit

Test your setup on ccloud³

Sign up for ccloud³ and receive €200 starting credit for your project.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Get started for free

Sign up and receive €200 credit at centron within your first 60 days.

This promotional offer applies to new accounts only. Available exclusively to businesses.