How to Easily Update Node.js to the Latest Version

How to Update Node.js to the Latest Version

Node.js is a popular open-source, cross-platform server-side environment for building robust applications. Since a vibrant community of contributors backs it, the platform is continuously updated to introduce new features, security patches, and other performance improvements. 

So, updating to the latest Node.js version can help you to make the most of the technology. You can decide to work with the Long-term Supported (LTS) version or the Current version that comes with the latest features. 

Typically, LTS is recommended for most users because it is a stable version that provides predictable update releases as well as a slower introduction of substantial changes. 

In this article, you will learn how to quickly and easily update Node.js on different operating systems—macOS, Linux, and Windows.

As we’ll demonstrate, there are many ways of updating to the next version of Node.js. So, you can choose the option that best meets your system requirements and preferences.

Checking your version of Node.js

Before getting started, you can check the version of Node.js currently deployed on your system by running the following command on the terminal:

   node –version

 

or (shortened method):

   node -v

 

Let’s now talk about the different ways on how to update Node.js.

 

1. Updating using a Node version manager on macOS or Linux

A Node version manager is a utility that lets you install different Node.js versions and switch flawlessly between them on your machine. You can also use it to update your version of Node.js.

On macOS or Linux, you can use either of the following Node version managers:

  • nvm
  • n

Let’s talk about each of them.

a) nvm

nvm is a script-based version manager for Node.js. To install it on macOS or Linux, you can use either Wget or cURL.

For Wget, run the following command on the terminal:

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

For cURL, run the following:

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

The above commands assume that you’re installing nvm version 0.35.3. So, you’ll need to check the latest version before installing it on your machine. 

With these commands, you can clone the repository to ~/.nvm. This way, you can make changes to your bash profile, allowing you to access nvm system-wide.

To confirm if the installation was successful, you can run the following command:

  command -v nvm

If everything went well, it’d output nvm.

Next, you can simply download and update to the latest Node.js version by running the following:

  nvm install node

 

Note that node refers to an alias of the latest Node.js version. 

You can also reference LTS versions in aliases as well as .nvmrc files using the notation lts/* for the most recent LTS releases. 

Here is an example:

  nvm install –lts

 

If you want to install and upgrade to a specific version, you can run the following:

  nvm install <version-number>

 

For example, if you want to update Node.js to version 12.18.3, you can run:

  nvm install 12.18.3

 

After the upgrade, you can set that version to be the default version to use throughout your system:

  nvm use 12.18.3

 

You can see the list of installed Node.js versions by running this command:

  nvm ls

Also, you can see the list of versions available for installation by running this command:

nvm ls-remote

 

b) n

n is another useful Node version manager you can use for updating Node.js on macOS and Linux. 

Since it’s an npm-based package, if you already have Node.js available on your environment, you can simply install it by running this command:

npm install -g n

Then, to download and update to your desired Node.js version, execute the following:

n <version-number>

 

For example, if you want to update Node.js to version 12.18.3, you can run:

n 12.18.3

To see a list of your downloaded Node.js versions, run n on its own:

    n

 

You can specify to update to the newest LTS version by running:

n lts

You can also specify to update to the latest current version by running:

You can specify to update to the newest LTS version by running:

n latest

 

2. Updating using a Node version manager on Windows

On Windows, you can use the following Node version manager:

  • nvm-windows

Let’s talk about it.

a) nvm-windows

nvm-windows is a Node version management tool for the Windows operating system. While it’s not the same as nvm, both tools share several usage similarities for Node.js version management.

Before installing nvm-windows, it’s recommended to uninstall any available Node.js versions from your machine. This will avoid potential conflict issues during installation.

Next, you can download and run the latest nvm-setup.zip installer.

Also, since the utility runs in an Admin shell, you’ll need to begin the Command Prompt or Powershell as an Administrator before using it. 

If you want to install and upgrade to a specific version, you can run the following:

You can specify to update to the newest LTS version by running:

nvm install <version-number>

 

For example, if you want to update Node.js to version 12.18.3, you can run:

nvm install 12.18.3

After the upgrade, you can switch to that version:

nvm use 12.18.3

You can also specify to update to the latest stable Node.js version:

nvm install latest

You can see the list of installed Node.js versions by running this command:

nvm list

Also, you can see the list of versions available for download by running this command:

nvm list available

 

3. Updating using a Node installer on Linux

Using a Node installer is the least recommended way of upgrading Node.js on Linux. Nonetheless, if it’s the only route you can use, then follow the following steps:

  • Go to the official Node.js downloads site, which has different Linux binary packages, and select your preferred built-in installer or source code. You can choose either the LTS releases or the latest current releases.
  • Download the binary package using your browser. Or, you can download it using the following Wget command on the terminal:

Wget command on the terminal

 

  • Download the binary package using your browser. Or, you can download it using the following Wget command on the terminal:
wget https://nodejs.org/dist/v12.18.3/node-v12.18.3-linux-x64.tar.xz

 

Remember to change the version number on the Wget command depending on the one you want.

  • Install the xz-utils utility using the following command:
sudo apt-get install xz-utils

This utility will be used for unpacking the binary package. 

 

  • Finally, run the following command to unpack and install the binary package on usr/local:
tar -C /usr/local -strip-components 1 -xJf node-v12.18.3-linux-x64.tar.xz

 

4. Updating using a Node installer on macOS and Windows

Another way of updating your Node.js on macOS and Windows is to go to the official download site and install the most recent version. This way, it’ll overwrite your existing old version with the latest one.

You can follow the following steps to update it using this method:

  • On the Node.js download page, select either the LTS version or the latest current version.

On the Node.js download page, select either the LTS version or the latest current version

  • Depending on your system, click either the Windows Installer option or the macOS installer option.

 

  • Run the installation wizard. It will magically complete the installation process and upgrade your Node.js version by replacing it with the new, updated one.

 

5. Updating using Homebrew on macOS

Homebrew is a popular package management utility for macOS. 

To use it for installing Node.js, run the following command on your macOS terminal:

brew install node

Later, if you’d like to update it, run the following commands:

brew update #ensure Homebrew is up to date first

 

brew upgrade node

 

Furthermore, you can switch between installed Node.js versions:

brew switch node 12.18.3

 

There is an easier way to upgrade Node.js Versions

Renovate is an open source tool by Mend for developers and DevOps that automatically creates pull requests (PRs) for dependency updates. Renovate PRs embed all the information you need to ease your update decision.

Renovate can upgrade the Node.js runtime and packages used by your project. This way you have access to the latest features, bug fixes, performance improvements, and security mitigations.

Get Renovate now. >>

Alfrick Opidi / About Author

Alfrick is an experienced full-stack web developer with a deep interest in taking technical information and converting it into easy to understand content. See him as a technology enthusiast who explores the latest developments in the industry and presents them in a relatable, concise, and decipherable manner.

LinkedIn