How to Update Node.js Versions on Linux

Keeping your Node.js version up to date is essential for security, performance, and access to the latest features. New releases often include bug fixes, optimizations, and improvements that can enhance your development workflow.

If you are running a Linux system, there are several ways to update Node.js. This guide will walk you through multiple methods, including using a package manager, Node Version Manager (nvm), NodeSource distribution binaries, and manually downloading the latest version.

Looking for instructions for macOS? Click here. Need help with Windows? Click here.

By the end of this article, you’ll have the latest version of Node.js running smoothly on your system—without breaking your existing projects. Let’s get started! 🚀

Check Your Current Node.js Version

Before updating Node.js, it’s important to check which version you currently have installed. You can do this by running the following command in your terminal or command prompt:

node -v

This will display the installed Node.js version, e.g., v22.11.0.

Understanding Node.js Release Lines: LTS vs. Current

Node.js follows a predictable release schedule with two main tracks:

  • LTS (Long-Term Support): Recommended for most users, especially for production environments. LTS versions receive security updates and bug fixes for an extended period. The LTS version at the moment is v22.
  • Current: Includes the latest features and improvements but may introduce breaking changes. It's ideal for developers who want early access to new capabilities. The current version at the moment, and until April 2025, is v23.

To determine whether your installed version is still actively maintained, visit the Node.js release schedule.

Method 1: Updating Node.js Using NodeSource Binary Distributions

Updating Node.js on Linux can be done efficiently using the NodeSource binary distributions, which provide a simple and reliable way to install and manage Node.js versions. NodeSource is the recommended way to install Node.js on Linux as it offers the most up-to-date and stable releases, including LTS and Current versions.

1. Add the NodeSource Repository

To update Node.js, you first need to ensure that the NodeSource repository is set up for the version you want to install. Follow the steps below to add the NodeSource repository and install or update Node.js:

For the Latest Node.js Version

Run the following command to add the NodeSource repository for the latest version of Node.js:

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

For the Latest LTS Version

If you prefer to install the latest LTS (Long-Term Support) version, use the LTS setup script instead:

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

This command will configure your system to download the desired Node.js version from the NodeSource repository.

For a specific version

If you want to install a specific version, for example v23, you can run the following command:

curl -fsSL https://deb.nodesource.com/setup_23.x -o nodesource_setup.sh

2. Install or Update Node.js

After adding the NodeSource repository, you can install or update Node.js with the following command:

sudo apt-get install -y nodejs

This will install the latest version of Node.js (either LTS or Current, depending on the script you ran).

3. Verify the Installation

After installation, you should verify that Node.js has been updated successfully. Use the following command to check the version:

node -v 

4. Install Additional Dependencies (Optional)

If you're working with native modules or need additional build tools (like make or gcc), you may want to install the build-essential package:

sudo apt-get install -y build-essential

This package includes the necessary tools to compile and install Node.js native modules, ensuring everything runs smoothly.

5. Removing Old Versions

If you’re using NodeSource and have multiple Node.js versions installed, you can remove older versions to free up space. To do this, you can use the following command:

sudo apt-get remove --purge nodejs

Then, proceed to reinstall the desired version using the steps outlined above.

Method 2: Updating Node.js Using NVM (Node Version Manager)

For users who work on multiple Node.js projects requiring different versions, nvm is the best solution.

Installing NVM (If Not Installed)

First, check if nvm is installed:

command -v nvm

If not, install it using:

curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
source ~/.bashrc # or ~/.zshrc

Updating Node.js with NVM

Once nvm is installed, you can update Node.js:

  1. Check available versions:
    nvm list-remote | tail -n 10
  2. Install the latest version:
    nvm install node
  3. Use the latest version:
    nvm use node
  4. Set it as the default:
    nvm alias default node

Method 3: Manually Downloading and Installing Node.js

If you prefer to manually install the latest version, you can do so from the official Node.js website.

Steps to Manually Update Node.js

  1. Download the latest Node.js binary:
    curl -fsSL https://nodejs.org/dist/latest/node-v23.8.0-linux-x64.tar.xz -o node.tar.xz
  2. Extract the file:
    tar -xf node.tar.xz
  3. Move the extracted files to /usr/local:
    sudo mv node-v20.8.0-linux-x64 /usr/local/nodejs
  4. Update your system’s PATH:
    echo 'export PATH=/usr/local/nodejs/bin:$PATH' >> ~/.bashrc
    source ~/.bashrc
  5. Verify the installation:
    node -v

Choosing the Best Update Method

  • If you want official binary distributions, use Method 1 (NodeSource Binaries) the best choice overall.
  • If you work with multiple Node.js versions, nvm (Method 2).
  • If you prefer a manual approach, follow Method 3.

Keeping your Node.js installation up to date ensures you have the latest features, security patches, and performance improvements. Choose the method that works best for your workflow and enjoy a smooth Node.js development experience on Linux!

By using NodeSource binaries, you can keep your Node.js version up-to-date on Linux with minimal effort, ensuring access to the latest features and security patches. This method is the recommended and most reliable approach for Linux users looking to update Node.js. For developers and organizations seeking enhanced security, performance monitoring, and reliability, N|Solid is the best solution. N|Solid is an enterprise-grade platform built on Node.js, offering real-time insights, vulnerability scanning, and advanced diagnostics to ensure your applications run securely and efficiently. With features like built-in CVE monitoring and proactive alerts, N|Solid helps teams stay ahead of security risks, even as the Node.js ecosystem evolves. It’s an invaluable tool for teams navigating the challenges of upgrading and maintaining Node.js applications.

The NodeSource platform offers a high-definition view of the performance, security and behavior of Node.js applications and functions.

Start for Free