DEV Community

Cover image for How to Update Node.js
Antonio Silva
Antonio Silva

Posted on

How to Update Node.js

To update Node.js on your system, follow the guide based on your environment:

Updating Node.js on Linux (including Ubuntu/Mint)

Using Node Version Manager (NVM)

This is the most flexible and recommended method, as it allows you to have multiple versions of Node.js installed and switch between them.

Installing NVM:

  • Open the terminal.
  • Run the command to install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

Enter fullscreen mode Exit fullscreen mode
  • After installation, reload the terminal environment:
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Check if NVM was installed correctly:

nvm --version
Enter fullscreen mode Exit fullscreen mode

Installing the latest version of Node.js:

  • Use the following command to list the available Node.js versions:
nvm ls-remote
Enter fullscreen mode Exit fullscreen mode
  • To install the latest version of Node.js:
nvm install node
Enter fullscreen mode Exit fullscreen mode

Or if you want a specific version, replace node with the desired version, for example:

nvm install 16.20.1
Enter fullscreen mode Exit fullscreen mode

Setting a default version:

After installing the desired version, you can set it as the default:

nvm use 16.20.1
nvm alias default 16.20.1
Enter fullscreen mode Exit fullscreen mode

Using official repositories (if you don't want to use NVM)

  • Add the NodeSource repository:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
Enter fullscreen mode Exit fullscreen mode

replace setup_lts.x with setup_18.x or setup_20.x for specific versions

  • Install Node.js:
sudo apt install -y nodejs
Enter fullscreen mode Exit fullscreen mode
  • Check if Node was updated:
node -v
Enter fullscreen mode Exit fullscreen mode

Updating on Windows (with or without NVM-Windows)

Using NVM-Windows

  • Download and install NVM for Windows.

  • After installation, use the terminal:

nvm install latest
Enter fullscreen mode Exit fullscreen mode
  • Set the version as default:
nvm use latest
Enter fullscreen mode Exit fullscreen mode

Using the Node.js Installer

  1. Go to the official Node.js website: nodejs.org.
  2. Download the latest version (LTS recommended).
  3. Run the installer and follow the instructions.

Updating on macOS

Using NVM (Node Version Manager)

  • Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Enter fullscreen mode Exit fullscreen mode
  • Activate NVM
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

or, if you're using zsh, use:

source ~/.zshrc
Enter fullscreen mode Exit fullscreen mode
  • Verify the installation
nvm --version
Enter fullscreen mode Exit fullscreen mode
  • Install or update Node.js
nvm install node
Enter fullscreen mode Exit fullscreen mode

Or, if you prefer a specific version:

nvm install 18.17.1
Enter fullscreen mode Exit fullscreen mode
  • Set the default version
nvm alias default 18.17.1
Enter fullscreen mode Exit fullscreen mode
  • Check the Node.js version
node -v
Enter fullscreen mode Exit fullscreen mode

Using Homebrew

  • Update Homebrew
brew update
Enter fullscreen mode Exit fullscreen mode
  • Update Node.js
brew upgrade node
Enter fullscreen mode Exit fullscreen mode
  • Install Node.js (if not installed)
brew install node
Enter fullscreen mode Exit fullscreen mode
  • Check the installed version
node -v
Enter fullscreen mode Exit fullscreen mode

Using the Node.js Installer

If you prefer a simple method, you can use the official installer:

  1. Go to the official Node.js website.
  2. Download the latest version (LTS is recommended).
  3. Follow the installer instructions to update Node.js.

Top comments (0)