How to Update Node.js: Linux, Windows, and Mac

Since its release back in 2009, Node.js has had nothing but a steady incline in use among web developers. With one of the largest open-source libraries in the world, this lightweight and efficient cross-platform, server-side environment for building high-scaling applications is considered one of the most powerful programming languages around. It uses event-driven, non-blocking I/O models, is built on Chrome’s V8 JavaScript engine, and is continuously updated with security and performance patches. In this article, we are going to cover how to update Node.js to its latest version on Linux OS, Windows 10, and macOS, using package managers and the Node Installer.

Package Managers and the Node Installer

Before we jump into the various steps involved with updating your Node.js version on the operating system that you have, it’s first important to note that there are many different routes you can go. We’re going to list these out so that you understand what we’re referring to later on in the article via the abbreviations used. All links below either lead to the official site for each or send you to a guide that explains how to install them.

  • Node Package Manager: the Node Package Manager (NPM) is a command line tool that installs, updates, and uninstalls Node.js packages. When you first install Node.js, you will also verify the NPM installation as well.
  • Node Version Manager: the Node Version Manager (NVM) is an open-source manager for Node.js that allows you to install different versions of Node.js and switch between them as needed on a per-shell basis.
  • Yarn Package Manager: Yarn is another package manager that is all about using and sharing code quickly, reliably, and securely with other developers. The package manager also doubles as a project manager, keeping all of your projects organized with sub-component capability. This is only good to use after you’ve already installed Node.js.
  • Homebrew Package Manager: the Homebrew utility is quite a popular one for macOS users. It is a “missing package manager” that is designed for macOS, and is commonly used to install Node.js. It can also be used on Linux machines as well.
  • Node.js Installer: this is a pre-built installer that works for installing Node.js across all platforms. It contains both the source code for Node.js, as well as installers for Windows, macOS, and Linux.

How to update Node.js on Linux machines

If you are running Linux OS and want to know how to update Node.js, the most successful methods to use are NVM and NPM. You can also use the Node Installer, which we will cover later in this article.

Using NVM to update Node.js on Linux

This step will walk you through updating the repositories of Node.js, downloading the dependencies needed, and installing NVM. We then provide steps on how to update Node.js.

  1. Open the Linux Terminal.
  2. Check your package repository with:
    sudo apt update
  3. Download the dependencies with:
    sudo apt install build-essential checkinstall libssl-dev
  4. Download NVM with:
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  5. Restart the Linux Terminal.
  6. Verify the NVM installation with:
    nvm -version
  7. Check the current version of Node.js with:
    nvm ls
  8. To check the latest releases, run the command:
    nvm ls -remote
  9. Find the latest version in the list and install using:
    nvm install [version.number]

Using NPM to update Node.js on Linux

  1. Open the Linux Terminal.
  2. Check your current version with:
    node -v
  3. Clear the cache with:
    npm cache clean -f
  4. Install the “n” module with:
    npm install -g n
  5. To install the latest stable version, use:
    sudo n stable
  6. To install the latest version (not necessarily stable), use:
    sudo n latest
  7. To install a specific version, use:
    n [version.number]

How to update Node.js on Windows 10

If you are running Windows 10 and are wondering how to update Node.js, the most successful methods to use are NPM and NVM-Windows.

Using NPM to update Node.js on Windows

  1. Launch Windows PowerShell as an Administrator.
  2. Enter the following command to install the n module:
    npm install -g n
  3. Enter the command below to install the stable version of Node.js:
    n stable
  4. To install the most recent version, use “n latest” as the command line instead of “n stable“.
  5. To install a specific version of Node.js, use “n [version number]” instead.
  6. If a prompt appears, agree to it.
  7. Wait for the installation to complete, and then close PowerShell.

Using NVM-Windows to update Node.js on Windows

It is important to note that NVM-Windows is different from NVM, and if you want to use this route, you must uninstall any other existing Node and NPM versions to avoid conflict. If you have installed NVM-Windows and want to know how to update Node.js with it, follow the steps below.

  1. Use either Command Prompt or PowerShell terminals.
  2. Make sure to run whichever you choose as an Administrator.
  3. To install the latest version, type in:
    nvm install latest
  4. Wait for the installation to complete, then close CMD or PowerShell.
  5. If you want to install a specific version, type in:
    nvm install [version number]
  6. You can see the installed versions by typing in:
    nvm list
  7. You can see the versions available to download by typing in:
    nvm list available
Update Node.js using NVM-Windows

How to update Node.js on macOS

If you are running macOS and want to update Node.js, the most likely methods are either to use NPM, Homebrew, or the Node.js installer. 

Using NPM to update Node.js on macOS

  1. Open your macOS Terminal.
  2. Type in the following command to install the n module:
    npm install -g n
  3. Then type in the following command to install the stable version of Node.js:
    n stable
  4. To install the most recent version, use:
    n latest
  5. To install a specific version of Node.js, use:
    n [version number]
  6. If a prompt appears, agree to it.
  7. Wait for the installation to complete, and then check the version installed by using the command, “node -v” in the Terminal.
  8. You can now close the Terminal.

Using Homebrew to Update Node.js on macOS

  1. Open your macOS Terminal.
  2. Enter the command below and agree to the prompts that come up:
    brew update
  3. Then enter the following command and again, agree to the prompts:
    brew upgrade node
  4. Allow the installation to complete.
  5. Close Terminal when it is done.
Update Node.js using Homebrew on macOS

Using NVM to update Node.js on macOS

  1. Open your macOS Terminal.
  2. Do you want the most recent, stable version? Enter command:
    nvm ls stable
  3. Do you want any other version of Node.js? Do one of the following:
    1. Enter in “nvm ls” to check the current installed version.
    2. Enter in “nvm ls -remote” to see available versions.
    3. Enter in “nvm install [version number]” to install the one you want.
  4.  Agree to the prompts that pop up.
  5. Once the installation has completed, you can check the installed version with “nvm ls” again.
  6. Close the Terminal when finished.

Update Node.js using the Node Installer on Linux, Windows, and MacOS

If you want to use the Node Installer to update your Node.js on Linux, Windows, or macOS, you will need to do the following.

Using the Node Installer on Linux machines

  1. Head to the Node.js downloads site, and select which Linux Binary you would like to use.
  2. Download the binary package using your internet browser.
Node Installer - Choose a Linux Binary Package to update Node.js on Linux
  1. If you’d like to download it via the Linux Terminal, use the following command:
    wget https://nodejs.org/dist/v14.18.1/node-v14.18.1-linux-x64.tar.xz
  2. You will need the xz-utils utility tool to unpack the binary package. To install this, run the command:
    sudo apt-get install xz-utils
  3. To unpack and install the binary package, run the following command:
    tar -C /usr/local -strip-components 1 -xJf node-v14.18.1-linux-x64.tar.xz

Using the Node Installer on macOS or Windows Machines

  1. Head to the Node.js downloads site, and select whether you’d like to install LTS or Current which has the latest features. LTS stands for Latest Stable Version.
  2. Once you’ve chosen which one you want, choose either MacOS or Windows Installer and download.
Node Installer - Choose macOS or Windows Installer to update Node.js on your macOS or Windows system
  1. Once the Node.js Installer is downloaded, run it.
  2. Follow the on-screen prompts to set it up via the Node.js Setup Wizard.
Node Installer - Setup Wizard
  1. You will need to accept the Node.js license.
  1. Now choose the file path where you’d like to install Node.js.
Node Installer - Choose File Path to Save
  1. Finally, select the way you’d like to install Node.js. We recommend using the Node.js Runtime.
Node Installer - Choose How to Install Node.js
  1. Hit next, and start the installation process.
  2. Once it is complete, you can use Terminal (macOS) or PowerShell (Windows) to check the version installed with the command, “node -v“.

Wrapping It Up

While there are numerous ways to update your Node.js, the process is quite easy to get used to and simple once you’ve done it a few times. Just make sure to keep checking your Node.js versions against the available version downloads to ensure that you have the latest stable version. Enjoy coding!

Leave a Comment