How to Upgrade NodeJS to Latest Version
- Using Linux Binaries to Upgrade NodeJS in Linux
- Using the Windows and macOS Installers to Upgrade Node Js
-
Upgrading Node Js Using the
NVM
Package on Linux and macOS -
Using the
n
Package to Upgrade Node Js -
Upgrading Node Js on Windows Using
NVM
Upgrading to and using the latest software versions is one of the best practices for developers to develop even more secure and performant software.
While security is also a top reason you should upgrade, you may not want to miss out on the new cool features often meant to make the developer experience even better.
Node js is a widely-used open source software with lots of contributions from some of the best software developers means that there are more frequent version releases. Some of these releases are intended to fix bugs, while others introduce new features.
The most recent Long Term Support(LTS)
version recommended for most users is 16.13.2LTS
, while the most current version with the latest features is 17.4.0
.
The LTS version, as the name suggests, is the most stable with continued support and is recommended for production use. However, for those who would like to get a taste of the latest cool features, then they should opt for the current release.
For those using v17.x, v16.x, v14.x, and v12.x, new security releases are meant to fix various vulnerabilities reported in recent times.
We can use several ways to upgrade to the latest version of Nodejs, depending on the operating system that we are using.
Using Linux Binaries to Upgrade NodeJS in Linux
Although it is one of the straightforward methods of upgrading Nodejs, it is also the least recommended method.
To get started, you need to visit the official node js website at Nodejs.org
and click on the downloads tab.
Here you’ll find installers for different operating systems. However, you’ll also note the two rows named Linux binaries at the bottom rows.
There are two types of Linux binaries provided depending on whether your computer is running a 64-bit processor architecture or the processor by Advanced RISC machines commonly abbreviated as ARM.
Now, download the appropriate package using the browser or the wget command shown below.
wget https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-x64.tar.xz
Since these are binary packages that we have just downloaded, we also need to install the xz-utils
, an open-source general-purpose compression software. We need to execute the command below in the terminal to do so.
sudo apt-get install xz-utils
To upgrade to the latest version of Node while unpacking this package simultaneously, we need to run the command below. In this case, we will be installing the x64
version of the Node js.
tar -C /usr/local -strip-components 1 -xJf node-v16.13.2-linux-x64.tar.xz
Using the Windows and macOS Installers to Upgrade Node Js
We can also upgrade Node js on Windows and macOS systems using the installers provided on the official website.
To get started, open the official nodejs page and navigate to the Downloads folder by clicking the downloads tab.
While on this page, download the installer for LTS, click the LTS section at the top before downloading the appropriate installer or the current version by first clicking on the current section before downloading the correct installer.
Once you have downloaded the installer upgrade to the latest version, open the installer and follow the instructions on the installation wizard step by step.
Upgrading Node Js Using the NVM
Package on Linux and macOS
The Node version manager is one of the best-known tools for managing Node js installations on Linux and macOS machines.
We can also upgrade to the latest version of Node js that we want using these tools.
However, we will first need the nvm device
installed on our systems using the cURL
or Wget
commands below.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Once we have this tool in place, we can upgrade to the Node js version we desire.
However, we first need to have the correct version and version number of Node js that we want to upgrade to before running the command below.
In this case, we are upgrading to the latest LTS
version of Node js.
nvm install 16.13.2
We can also use an alias of the latest version of Node js to upgrade to the newest version, as shown here.
nvm install node
Using the n
Package to Upgrade Node Js
Then the package is also one of the best tools for managing Node js in UNIX-like
systems.
Its installation is straightforward since we need to have the npm installed beforehand and then run the command below to get it installed globally.
npm install -g n
We can use the command below to upgrade to the latest LTS
version.
n lts
We can also upgrade to the latest current version of Node js by running the command below.
n latest
Finally, we can also upgrade to a specific version by specifying the version number we want to upgrade to, as shown below.
n 16.13.2
Upgrading Node Js on Windows Using NVM
The nvm tool available on Linux and macOS systems is not natively supported on Windows platforms. However, a similar alternative tool that we can use to upgrade Node js is the nvm-window
utility tool.
We can download this tool from the windows-nvm repository and follow the instructions provided in the README.md
file to install it.
Once we have the tool in place, we can upgrade to the latest stable version of Node js by running the command below.
nvm install latest
We can also upgrade to a specific LTS
version or the latest version by specifying the version number as shown here.
nvm install 16.13.2
Isaac Tony is a professional software developer and technical writer fascinated by Tech and productivity. He helps large technical organizations communicate their message clearly through writing.
LinkedIn