Upgrading your current version of Node.js to the latest version has a lot of benefits, including new functionalities and security.
Here are four ways to update the node version on Mac.
- Using N: An npm-based node version manager.
- Using Homebrew: Type this command: brew upgrade node
- Using NVM: A script-based node version manager.
- Using MacPorts: MacPorts is the other package manager for Mac.
Method 1: Update Node using N
N is an npm-based node version manager. I assume you already have a node version installed on your machine. To install the first node version, you can run the following command.
sudo npm install -g n
Assuming you have successfully installed n. It is the simplest way.
The following command will install the latest version of the node. Please hit that command in admin mode.
sudo n latest
It will install the latest version of Node.js.
Method 2: Using homebrew
To update the Node version on Mac, use the brew upgrade node command. The Homebrew is one of the popular package managers for MacOS. If you are using a Mac, Homebrew is the package manager to install different packages.
Assuming you previously installed Node, the following command will update you with formulae and upgrade you to the latest Node.js version.
brew update brew upgrade node
It will install the latest version of Node.js.
Method 3: Update Node using NVM
NVM is the script-based node version manager. The documentation describes how to install it easily using the curl and bash one-liner. It’s also available on the Homebrew package manager.
If you have not installed NVM, then you need to install it first.
You can install NVM using Homebrew with the following command.
brew install nvm
Now the following command will install the latest version of the node.
nvm install node
To switch from the old Node.js version to the new Node.js version, use the below command:
nvm alias default node
Now, if you check the current version of the Node.js, you will get the latest version:
node --version v22.2.0
Method 4: Using MacPorts
MacPorts is the other Mac package manager. The following will update the local ports tree to access updated versions. Then, it will install the latest version of Node.js. This works even if you have a previous version of the package installed.
sudo port selfupdate sudo port install nodejs-devel
That’s it.
Joe
Krunal, thanks for the post.
When I run ‘sudo n latest’ I receive the following message:
installed : v13.12.0 to /usr/local/bin/node
active : v6.13.1 at /Users//miniconda3/bin/node
How can I update the active Node?