How to Update Node.js Version {Linux, Windows, & macOS}

Introduction

Node.js is an open-source JavaScript runtime environment. Since Node.js has an active user community, minor software updates are released frequently.

Update Node.js regularly to ensure system security, latest features, and bug fixes. The steps to update to a newer version differ depending on the operating system.

This article will show how to update Node.js on Linux, Windows, and macOS.

How to update Node.js version on Linux, Windows, and macOS - a tutorial.

Prerequisites

How to Update Node.js on Linux

There are different ways to update Node.js on a Linux-based system. The Node Version Manager (nvm) is the easiest and recommended option. However, you can also update with the local package manager or the binary packages.

The sections below outline the steps for each method.

Update Node.js with NVM

The best and easiest way to upgrade Node.js is with nvm, a practical tool for managing multiple Node.js versions. Follow these steps:

1. Start by updating the system package repository:

sudo apt update

2. Install nvm using the curl command:

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

Note: If you don't have curl, install it by running the command:

sudo apt install curl

Alternatively, use wget and run the command:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash

Running either of the commands above downloads a script that installs or updates nvm on your machine.

3. Close and reopen the terminal for the system to recognize the changes, or run the command below:

source ~/.bashrc

4. Verify that nvm has been successfully installed:

nvm --version
nvm --version 0.40.0 terminal output

5. Before upgrading Node.js, check which version you have on the system:

nvm ls

6. Now you can check for the available releases by running:

nvm ls-remote
nvm ls-remote latest version nodejs

The output is a list of all available releases. Scroll down to the bottom of the list to find the latest one.

7. To install the latest version, use the nvm command with the specific Node.js version:

nvm install [version_number]

For example:

nvm install 22.6.0 terminal output

8. If there are multiple Node.js versions, use the following command to list installed versions:

nvm ls

Then, switch to a specific version with:

nvm use [version_number]
nvm use 22 terminal output

Update Node.js with n

Alternatively, use Node's official package manager to install the n package and update Node.js.

Note: Learn the difference between Yarn and NPM, two package managers for Node.js.

By adding the n package, you can interactively manage different Node.js versions.

Follow the steps below to update Node.js using the n module:

1. Clear the npm cache:

npm cache clean -f
npm cache clean -f terminal output

2. Install n, Node's version manager:

sudo npm install -g n
sudo npm install -g n terminal output

The command installs the n package globally for all users.

3. With the n module installed, you can:

  • Install the latest stable version:
sudo n lts
  • Install the latest release:
sudo n latest
  • Install a specific version:
sudo n [version_number]

For example:

sudo n latest terminal output

4. To switch between installed versions, run n without any options:

sudo n
sudo n node versions

The command opens a prompt for choosing between installed Node.js versions. Use the arrow keys to navigate and Enter or Space to select.

Update Node.js with APT

APT is the default package manager for Ubuntu and Debian-based distributions. It typically does not have the latest Node.js version in the repository.

Follow the steps below to add the LTS version and update Node.js using the APT package manager:

1. Install the NodeSource PPA to add the latest available DEB package to the APT repository:

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - 
node 20 nodesource ppa curl output

The script also installs any required prerequisites.

2. Update the system package repository:

sudo apt update

3. Run the command below to update Node.js:

sudo apt install nodejs
sudo apt install nodejs ppa terminal output

When prompted, type y and press Enter to continue the installation. Wait for the process to complete.

4. Verify that the update was successful by checking the Node.js version:

node -v
node -v ppa 20.16.0 terminal output

Update Node.js with Binary Packages

Updating Node.js with binary packages is the least recommended option. It doesn't resolve dependencies, and compared to updating via a package manager, it offers poorer security and more complex management.

However, if you use an environment without package managers, follow the steps outlined below to update Node.js using binary packages.

1. Navigate to Node's official prebuild binaries downloads page. Choose the appropriate version, OS, and system architecture.

Node.js website prebuilt binaries download Linux 22.6.0

2. Download the package by clicking the button. Alternatively, copy the download link and use the wget command. For example:

wget https://nodejs.org/dist/v22.6.0/node-v22.6.0-linux-x64.tar.xz
wget nodejs 22.6.0 binary download terminal output

Adjust the version number and link in the command to download a different version.

3. Extract and install the package using the syntax below:

sudo tar -C /usr/local --strip-components 1 -xJf [package_name]

For example:

sudo tar -C /usr/local --strip-components 1 -xJf node-v22.6.0-linux-x64.tar.xz

The command extracts and installs the downloaded package in the /usr/local directory. If you prefer a different location, adjust the directory in the command.

4. Check the Node.js version to confirm the installation worked:

/usr/local/bin/node -v
binary node installed v22.6.0

The command shows the installed Node.js version.

5. To avoid using the program location when running the command, add the /usr/local directory to PATH:

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

Adding the location to PATH tells the shell to look for the program in the listed location.

6. To apply the changes, restart the shell or reload the shell configuration:

source ~/.bashrc

Use the node command without the path.

How to Update Node.js on macOS

Updating Node.js on macOS can be done in three ways:

  • Using the macOS installer.
  • Updating without Homebrew.
  • Updating with Homebrew.

The sections below explain each method in detail.

Update Node.js with macOS Installer

A manual update involves downloading the installer from the official website and updating the app using the installation wizard. A manual update gives you direct control over the process.

Follow the steps below:

1. Navigate to the official Node.js website and download the macOS installer for the latest version. Choose the LTS (long-term support) version for the latest stable version or the Current version for bleeding-edge features.

Node.js website prebuilt installed download macOS

2. Double-click the file to run the installation wizard. Accept the license agreement, choose the destination folder, and select the features to install.

3. When the process completes, verify the installation by running the command below:

node -v
Checking the Node.js version on macOS.

Update Node.js without Homebrew

If you have previously installed nvm or n packages, use them to update Node.js, and select which version to use.

Via nvm

Node Version Manager (nvm) is a tool that allows you to manage multiple installations of Node.js on a single machine. Follow the steps below to update Node.js using nvm:

1. Check the currently installed Node.js version:

nvm ls
Checking which Node.js versions are currently installed on macOS.

2. Run the command below to install the latest stable Node.js version:

nvm install node
Installing Node.js with nvm on macOS.

3. Once the installation is complete, switch to the newly installed Node.js version using the syntax below:

nvm use [version]

Replace [version] with the version number you installed to activate it.

Via n

n is another Node.js version manager. It is similar to nvm but simpler and more lightweight, making it more straightforward to use than nvm.

Follow the steps below to update Node.js using n:

1. Install n using npm if you do not have it installed yet. Run the command below:

sudo npm install -g n
Installing the n version manager on macOS.

2. Update Node.js using one of the commands below, depending on your preference:

  • To install the latest stable node release, run:
sudo n stable
  • To install the latest node release:
sudo n latest
  • To install the latest LTS node release:
sudo n lts

For example, we will update Node.js to the latest stable release:

Updating Node.js on macOS with n.

Update Node.js with Homebrew

If you installed Node.js through the Homebrew package manager, follow the steps below to update it:

1. Open the Terminal app from the Applications/Utilities folder and update Homebrew to get the latest package available in the repository. Run the following command:

brew update

2. When the process completes, run the command below to update Node.js:

brew upgrade node
Upgrading Node.js with Brew on macOS.

After the upgrade process completes, verify the Node.js version by running:

node -v

The command should display the updated version number.

3. Optionally, update npm as well by running:

npm install -g npm
Upgrading npm on macOS.

How to Update Node.js on Windows

In Windows, there are three ways to update Node.js:

  • Using a Windows installer.
  • Using nvm.
  • Via the Chocolatey package manager.

The sections below show all methods for updating Node.js on a Windows machine.

Update Node.js with Windows Installer

One way to update Node.js is to go to the official download page and install the newest release. By updating this way, the system overwrites the older version with the newer one.

Follow the steps below:

1. Navigate to the official Node.js website and download the LTS (latest stable version) or Current (latest version with newest features) program version installer for Windows.

Nodej.s website prebuilt installer download Windows 22.6.0

2. Run the installer (.msi file). The action opens the setup wizard. Click Next on the Welcome screen to continue:

Node.js installation welcome screen.

3. Check the box to accept the terms in the License Agreement and click Next to continue.

Accepting the Node.js License agreement.

4. In the following steps, choose the destination folder, the features you want to install/update, and decide if you want to install/update tools for native modules (Chocolatey, Python, and Visual Studio Build Tools). When you finish configuring, click Install to install the update:

Installing Node.js on Windows using the Windows installer.

Wait for the process to complete and click Finish to exit the installer.

5. After installation, open a PowerShell or command-prompt window and run:

node -v
Windows node -v 22.6.0 output

The output shows the new version number, confirming that Node.js has been successfully updated.

Note: Sometimes, the system fails to overwrite the older Node.js release, and you may end up with two versions. If such problems occur, consider removing the old version or updating with NVM, as outlined in the section below.

6. Run the following command in a command prompt or PowerShell window to update npm:

npm install -g npm@latest

Although npm usually comes bundled with Node.js, it is a good idea to update it to the latest version if it has not been automatically updated.

Update Node.js using nvm

Install nvm to update Node.js on Windows. The tool allows you to install and manage multiple Node.js versions on your system.

Follow the steps below:

1. Navigate to the GitHub nvm releases page and scroll down to the Assets section. From the list, choose your preferred installation method. For this tutorial, we will use the executable file:

Downloading nvm for Windows.

2. Open the installer, accept the license agreement, and specify the installation destination and the symlink folder. You can leave all the default settings and click Install when finished.

Installing nvm for Windows.

3. If Node.js is already installed on the system, the wizard asks if you want nvm to control the installed version. Click Yes to continue with the installation.

Using nvm to control Node.js on Windows.

Wait for the installation to complete and click Finish to exit the installer.

4. Open a command prompt or PowerShell window and use the syntax below to update Node.js with nvm:

nvm install [version_number]

Replace [version_number] with the program version you want to install. For example:

nvm install 20 cmd output

5. To activate the installed version, use the syntax below:

nvm use [version_number]

Update Node.js with Chocolatey

Chocolatey is a popular Linux-style package manager for Windows. To update Node.js with Chocolatey, follow the steps below:

1. Open the Command Prompt or PowerShell as Administrator to ensure you have the necessary permissions.

2. Before updating Node.js, ensure that Chocolatey is up-to-date:

choco upgrade chocolatey
choco upgrade chocolatey upgraded latest

If prompted, type y and press Enter to upgrade Chocolatey.

3. Once updated, search for available Node.js packages:

choco find nodejs.install
choco find nodejs.install cmd output

The output shows the available versions.

4. Upgrade to the latest program version using the syntax below:

choco upgrade nodejs.install

For example:

choco upgrade nodejs.install latest

If prompted, press y and Enter to run the installation script. The command upgrades Node.js to the latest available version.

Conclusion

This guide showed how to update Node.js to the latest version on your system. Updating Node.js improves performance, security, and compatibility with the latest features and libraries.

Next, check out our tutorial for building a Node.js app with Docker, or learn how to install and set up the MEAN stack on Ubuntu.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
Next you should read
How To Install Node.js & NPM on Ubuntu 18.04
March 18, 2019

Node.js is an open-source cross-platform JavaScript (JS) runtime environment. It is used for building fast...
Read more
How to Install & Setup MEAN Stack on Ubuntu (MongoDB, Express.JS, Angular.JS, Node.JS)
March 28, 2024

The MEAN stack is an open-source JavaScript (JS) framework used for developing robust web applications. It is...
Read more
How to Install Node.js and NPM on CentOS 7
June 29, 2019

Node Package Manager (npm) is Node's official package manager, used for installing and managing packages...
Read more
How to Install Node.js and NPM on Windows
December 28, 2023

Node.js is a software application that runs JavaScript code. It's typically used for running scripts on the...
Read more