Introduction
Node with Homebrew ? This piece aims to demonstrate how to switch between multiple Node versions using Homebrew, a useful tool when working on multiple projects that require different versions of Node. With Homebrew, you can seamlessly switch between various Node versions to ensure compatibility across all of your projects.
What is Homebrew?
According to Homebrew website, Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s operating system, macOS, as well as Linux. The name is intended to suggest the idea of building software on the Mac depending on the user’s taste.
Since we use Homebrew to install NodeJS on our system, we are able to switch between multiple version of Node using Homebrew itself as well.
Switch Between Multiple Versions of Node with Homebrew
You may use these steps to install a different version of node:
If you want to check your current node version first, you may use the “node -v
” command. Then, search for your desired package.
"brew search node"
Choose the version you would like to install, in this example, we are going to install the older Node version 14.
brew install node@14
Then, unlink your current node version which is also the latest you installed using brew. And supposedly, the latest version would be the once without the version number.
brew unlink node
Now, link the older version of node you just installed, as mentioned earlier, we are going to use version 14.
brew link node@14
And if you want to use version 16, just change the version number, eg. brew link node@16
Sometimes it might be required to link them with the --force
and --overwrite
options: (Optional)
brew link --force --overwrite node@14
Lastly, update bash profile to point to OLD version (replace .zshrc with .bashrc or similar, depending on which $SHELL
you use)
echo 'export PATH="/usr/local/opt/node@14/bin:$PATH"' >> ~/.zshrc
Now, you may check your current node version again by running node -v
In Conclusion
Switching Node version using homebrew is safe and easy. There are other ways to switch Node version on your MacOS without using homebrew as well and we will talk about it in another article.
Sometimes, you might encounter some errors while installing node via Brew. You may check out this article if you’re facing this error : “post-install step did not complete successfully“
One thought on “How to Switch Between Multiple Versions of Node With Homebrew”
Comments are closed.