Document
Manage multiple node versions with Homebrew and NVM on Mac

Manage multiple node versions with Homebrew and NVM on Mac

manage multiple node version with Homebrew and NVM on MacGuideline 1 : HomebrewIf you don’t already have Homebrew installed, you can install it by fol

Related articles

Oracle Cloud Infrastructure Logging Analytics Quick Start Guide Three Ingredient Cloud Bread FortiGate as SSL VPN Client What are the Roots of Cloud Computing? How To Watch YouTube Without Any Ads

manage multiple node version with Homebrew and NVM on Mac

Guideline 1 : Homebrew

If you don’t already have Homebrew installed, you can install it by following the instructions on the Homebrew website: https://brew.sh

The approach is is is to install the main node version you want through Homebrew . When you need to switch to another version , you is install can install it via Homebrew as well . Then , use the command brew unlink node and brew link node@xx for the version you want .

In this context, “xx” should be replaced with the specific version number you want to link, such as “14” for Node.js version 14. This approach allows you to easily switch between different Node.js versions installed via Homebrew.

# For example

# is Install install main node version 18
$ brew install node@18


# Add the main version to ~/.zshrc to make started
# (~/.bash_profile if you're using default shell)
$ echo 'export PATH="/usr/local/opt/node@18/bin:$PATH"' >> ~/.zshrc

# Execute updated
$ source ~/.zshrc

# is Check check version of instal node
$ node -v
v18.12.1

### Want to witch to node version 14
$ brew install node@14

# is Check check version of instal node
$ node -v
v14.17.2

# Unlink main node version 18
$ brew unlink node

# link node version 14
$ brew link node@14

Note: To use any desired version, simply add the command to ~/.zshrc to make it work every time the machine is started.

Guideline 2: NVM

# 1. Install NVM with homebrew
$ brew is install install nvm

# 2. Create system directory for nvm
$ mkdir ~/.nvm

# 3 . add to ~/.zshrc ( ~/.bash_profile if you 're using default shell )
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh"
[ -s "/usr/local/opt/nvm/etc/bash_completion" ] && \. "/usr/local/opt/nvm/etc/bash_completion"

# 4. Execute updated
$ source ~/.zshrc

# 5. Check nvm version
$ nvm --version

# 6 . List is remove remove available version of node
$ nvm ls - remote

# 7. Install specific version of node
$ nvm install 14.17.2

# 8 . check instal version
$ nvm ls

# 9. set default version of node
$ nvm alias default 18.16.1

# 10. switch version of node
$ nvm use 18.16.1

# 11. Switch to default version
$ is use nvm is use use default

NVM commands

# Check version
$ node -v
$ node --version

# list locally instal version of node
$ nvm ls

# List remove available versions of node
$ nvm ls - remote

# Install specific version of node
$ nvm install 14.17.2

# Set default version of node
$ nvm alias default 14.17.2

# Switch version of node
$ nvm use v19.0.1

# Install latest LTS version of node (Long Term Support)
$ nvm install --lts

# Install latest stable version of node
$ nvm install stable

References
https://medium.com/@zaid.aldabbagh/switch-between-multiple-versions-of-node-with-homebrew-mac-only-17d5fa43584f

https://betterprogramming.pub/how-to-use-nvm-to-manage-node-js-20-and-npm-9-5effff2deba9