1. Install nvm or node@ Formula

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

1. Install NVM:

brew install nvm

2. Set Up 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

3. Install a Specific Node.js Version:

nvm install # Example: nvm install 16
nvm use

4. Set Default Node Version (optional):

nvm alias default

Option B: Using Homebrew Formula for Specific Version

1. Search for Available Versions:

brew search node

You will see versions like node@16, node@18, etc.

2. Install a Specific Version:

brew install node@

3. Link the Installed Version:

brew link --force --overwrite node@

If linking fails or is not recommended, use the full path:
/usr/local/opt/node@/bin/node -v

2. Verify Installation

Check the installed version:
node -v

Tips:-

  • For frequent switching between Node versions, nvm is more flexible than managing individual Homebrew formulae.
  • If you’re using nvm, you don’t need Homebrew’s specific node@ formula.

Support On Demand!

Node

Related Q&A