How to Update Node.js on Linux, macOS, and Windows

How-to-update-nodejs
How-to-update-nodejs

This guide describes how to download a new version of Node.js and update an installed version of Node.js on Linux, macOS, and Windows using multiple methods.

💦
Create a Linode account to try this guide with a $100 credit.This credit will be applied to any valid services used during your first 60 days.

Node.js is a cross-platform runtime environment for server-side JavaScript applications. Node.js uses the V8 JavaScript engine and is very popular. It is regularly updated for security and improvements, and should be kept updated on your systems.

Before You Begin

This guide assumes you are already running Node.js on your Linode or local workstation and are updating the version. If you don't have it installed, see the How to Install Node.js guide.

Install NPM, which installs by default with Node.js.

Update your system:

sudo apt-get update && sudo apt-get upgrade

Update your local workstation's system using the tools and package managers for the operating system.

If you're using the installer to update, go to the Node.js downloads page to get the appropriate version. The most recent version of long-term support (LTS) is listed and you also have the option to choose a version in the Current section.

The Node.js downloads page

Note:
Current is for developers and development or testing environments that don't require the systems to be as stable or up and accessible. LTS is aimed at production environments that require stability and continued uptime. If you are unsure which you need, choose LTS.

Updating the Node.js version using NPM

NPM is installed by default with Node.js and is the easiest way to update to any new version on Linux, macOS, or Windows when you do not need to use multiple versions.

Open the Terminal on Linux or macOS. On Windows, launch the Windows PowerShell as an administrator. Search for it in the search bar and then either right-click or click on the arrow to the right and choose Run as Administrator.

Enter the command npm install -g n to install the n module, a Node.js version manager.

Now that n is installed, enter n stable in the Terminal or PowerShell to install the stable version of Node.js

  • You can also use n latest for the most recent version, or n [version number] if you have a specific version you need to install.

Agree to any prompts that appears.

When the installation is complete, check the version installed with node -v.

Close the Terminal or PowerShell when finished.

Updating the Node.js version using NVM

If you need to install NVM, check out this guide How to Install and Use the Node Version Manager. It's a useful tool to have, especially in a development environment or if you have to use multiple versions of Node.js.

Open the Terminal on Linux or macOS. On Windows, launch the Windows PowerShell as an administrator. Search for it in the search bar and then either right-click or click on the arrow to the right and choose Run as Administrator.

If you only need the most recent stable version, enter the command nvm ls stable.

  • If you need something other than the stable version:
    a. Enter the command nvm ls to check what version you have.
    d. Enter the command nvm ls -remote to see what versions are available. Note the one you need.
    c. Enter the command nvm install [version number]

Agree to any prompts that appears.

When the installation is complete, check the version installed with nvm ls.

Close the Terminal or PowerShell when finished.

Updating the Node.js version on macOS

Using Homebrew

If you installed Node.js using Homebrew, then updating is easy.

Open the Terminal.

Enter the command brew update and agree to any prompts.

Enter the command brew upgrade node and agree to any prompts.

Quit the Terminal when finished.

Using the Node.js Installer

Open the installer from your Downloads folder and click Continue.

If you agree with it, accept the license by clicking Continue and Agree.

If you need to change the installation location, do so. Also, if you want to customize the installation, choose Customize. Linode recommends using the Standard Installation. Click Continue.

The installation is finished. Click Close and macOS moves the installer to the Trash.

Updating the Node.js version on Windows

Using Chocolatey

Assuming you installed Chocolatey when originally installing Node.js, updating should move quickly. Otherwise, update using the following installer instructions.

Launch the Windows PowerShell as an administrator. Search for it in the search bar and then either right-click or click on the arrow to the right and choose Run as Administrator.

When the command prompt loads, enter the following command:

choco upgrade nodejs.install

Accept any prompts that requires permission.

Close PowerShell when finished.

Using the Node.js Installer

Open the installer from your Downloads folder and click Next.

If you agree with it, accept the license by checking the box next to I accept the terms in the License Agreement and click Next.

If you need to change the installation location, do so now and click Next.

Choose the packages to install Linode recommends all of them, which is the default. You are prompted to check a box to Automatically install the necessary tools. Do so and click Next.

After installation is complete move the installer to the Recycle Bin.

Create a Linode account to try this guide with a $100 credit!

Conclusion

In this guide, you have seen how you can download a new version of Node.JS and update an existing version on Linux, macOS, and Windows operating systems using different methods.

If you found the article helpful, make sure to share it with interested parties and See you in the next one.

Thanks for reading : )

If you enjoy our content, please consider buying us a coffee to support our work:

Source: Linode Docs
License: CC 4.0
Changes Applied: None
Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.