Upgrading Node.js via the terminal (NVM or brew)

RMAG news

Upgrading Node.js via the terminal depends on the operating system you’re using. Here are instructions for some common environments: macOS, Linux, and Windows.

macOS and Linux

Using Node Version Manager (nvm)

Install nvm (if not already installed):

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

– Follow the instructions in the terminal to add `nvm` to your shell profile (`.bashrc`, `.zshrc`, etc.).

Reload your shell profile:

source ~/.bashrc # or ~/.zshrc, ~/.profile, etc.

Install the latest Node.js version:

nvm install node

– Alternatively, you can specify a version:
“`sh
nvm install 16.17.0 # replace with the desired version
“`

Use the installed version:

nvm use node

Set the default version (optional):

nvm alias default node

Using Homebrew (macOS only)

Update Homebrew:

brew update

Upgrade Node.js:

brew upgrade node

Windows

Using nvm-windows

Download nvm-windows from the nvm-windows releases page.

Install nvm-windows by running the installer.

Open Command Prompt or PowerShell as Administrator.

Install the desired Node.js version:

nvm install latest

– Alternatively, you can specify a version:
“`sh
nvm install 16.17.0 # replace with the desired version
“`

Use the installed version:

nvm use latest

Verifying Installation

After upgrading, verify the installed Node.js version by running:

node -v

This should output the version of Node.js that you have just installed.

By following these steps, you should be able to upgrade Node.js to the desired version on your system.