How to Update Node.Js to Any Version? How To Update Node.Js To Latest Version?

Shubham Vaidya
3 min readSep 10, 2020

--

Node.js is an open-source JavaScript runtime environment. Since Node.js has an active community of users, minor updates of the software come out every few weeks.

You may be using Node.js as a layer of the MEAN stack or in a different JS framework. Either way, make sure to update Node.js regularly to ensure system security.

There are several ways to install Node.js and NPM. Likewise, there are several ways to update your Node.js version, depending on the operating system running on your machine.

In this article, you will learn how to update to the latest Node.js version on Linux.

3 Ways to Update Node.js to Latest Version on Linux Systems

There are different ways to update Node.js if you are using a Linux-based system. Although using the Node Version Manager is the easiest and most recommended option, you can also update with the local package manager or by downloading the binary packages.

Option 1: Update Node.js with NVM (Node Version Manager)

The best way to upgrade Node.js is with NVM, a practical tool for managing multiple Node.js versions.

  1. Start by updating the package repository with the command:
sudo apt update

2. Download the following dependencies by typing:

sudo apt install build-essential checkinstall libssl-dev

3. Install NVM using the curl command:

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

4. Close and reopen the terminal.

5. Then, verify if you have successfully installed NVM:

nvm --version

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

nvm ls

7. Now you can check for newly available releases with:

nvm ls-remote

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

nvm install [version.number]

Option 2: Update Node.js with NPM (Node Package Manager)

As an alternative, you can use Node’s official package manager to update Node.js. NPM is a tool for installing and managing package dependencies.

If you have Node on your system, you have NPM, as well. With the npm command, you can check running Node.js versions and install the latest release.

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

1. First, clear the npm cache:

npm cache clean -f

2. Install n, Node’s version manager:

npm install -g n

3. With the n module installed, you can use it to:

  • Install the latest stable version: n stable
  • Install the latest release: n latest
  • Install a specific version: n [version.number]

Option 3: Update Node.js with Binary Packages

Updating Node.js with binary packages is the least recommended option. However, if it is the only way you can upgrade to the latest Node.js version, follow the steps outlined below.

1. Navigate to Node’s official downloads page where you can find all available packages. There you can download the source code or pre-built installer for the LTS versions or the latest release.

2. You can either download the package from your browser or find the version number you need and add it to the wget command:

wget https://nodejs.org/dist/v12.13.1/node-v12.13.1-linux-x64.tar.xz

3. Install xz-utils used to extract the binary package:

sudo apt-get install xz-utils

4. Extract and install the package with the command:

tar -C /usr/local –strip-components 1 -xJf node-v12.13.1-linux-x64.tar.xz

Thank you for reading this far. If you enjoyed this post, please share, comment, and press that 👏 a few times (up to 50 times). . . Maybe it will help someone.

--

--