Homebrew itself doesn’t manage multiple versions directly, but you can either use nvm (Node Version Manager) or install a specific version formula (node@
Option A: Using nvm
brew install nvm
Add the following lines to your shell configuration file (~/.zshrc or ~/.bashrc):
export NVM_DIR="$HOME/.nvm"
[ -s "$(brew --prefix nvm)/nvm.sh" ] && \. "$(brew --prefix nvm)/nvm.sh"
Then reload your shell:
source ~/.zshrc
nvm install
nvm use
nvm alias default
Option B: Using Homebrew Formula for Specific Version
brew search node
You will see versions like node@16, node@18, etc.
brew install node@
brew link --force --overwrite node@
If linking fails or is not recommended, use the full path:
/usr/local/opt/node@
Check the installed version:
node -v