Find out how to properly upgrade the Node.js version you have installed.
Node.js can be installed in multiple ways on a system, and the upgrade instructions depend on how you first installed it.
Upgrading Node.js If You Installed it Using the Official Package
The easiest way to install Node is to download the official package from the Node.js website. The official package contains an installer that will detect the existing version of Node.js and overwrite it with the new one.
Upgrading Node.js If You Installed it Using Homebrew (on macOS)
If you installed Node using Homebrew, upgrading Node is as simple as running the following commands in your terminal:
brew update # makes sure Homebrew is up to date
brew upgrade node
Homebrew might ask you to upgrade your xCode version to compile the package.
Upgrading Node.js If You Use nvm
nvm
is a popular way to run Node.js. It allows you to easily switch the Node version, install new versions, and rollback if something breaks.
To check the current version you are running, use the command nvm current
, which will give you the same result as node -v
.
To list all the installed versions, run nvm ls
.
To install a new Node release or an old Node release, use the command nvm install <VERSION>
. For example:
nvm install 10.8.3
Once installed, set the Node.js version to be the default by typing:
nvm use 10.8.3
This will set 10.8.3 as the default Node version system-wide.