Vannkorn

Full Stack Web Developer

Close

Switch between Node Js versions on Mac using Brew

Switching Node Js version is one of the routines for developer, mainly with those who maintain existing projects.

Ads: Register now via this link to receive $100 credit from Vultr

As a developer, there are chances when we need to switch between Node Js versions to be compatible with the configuration the previous dev has made.

There are various tools available to do so such as NVM and Brew, just to name a few.

In my case, as a Mac user, I prefer Brew, the Package Manager for Mac, to manage every package needed on my machine.

Let’s assume I have already installed the latest version of Node Js, which is 21.4.0 at the time of this writing, and I wish to install another version, let’s say version 16.

To do so, install Node Js version 16 with the following command:

brew install node@16

Now that I have 2 versions of Node Js on my local environment, the active one is @21 not the newly installed @16.

To switch to @16, first I need to unlink the @21 with the following command:

brew unlink node

It will unlink any node version, not limited to @21. Then I’ll tell Brew to use the @16 version:

brew link --overwrite node@16

Test with node -v to verify

Another Solution

I’ve found faster way to achieve this by installing n – npm, the Node.js version management: no subshells, no profile setup, no convoluted API, just simple.

Install it and just run

npm install -g n
n

Then the switching prompt pops up allowing you to choose between versions by just hitting the up and down button.

To install other versions using n – npm, just type ‘n’ following the version number. Like this

That’s it!!!

Leave a Reply

Your email address will not be published. Required fields are marked *