This article goes over solutions for managing multiple versions of Node.js on macOS. We'll start with a solution that I felt was straightforward and easily manageable. This is a living article and other solutions may be added over time. This solution was pulled from
and this article is meant as a public personal reference.Assumptions
- HomeBrew is installed
- general understanding of bash/zsh profiles
Install Desired Node Versions
brew install node@<version>
Example
brew install node@16
The default brew install node
installed the latest version
Useful CLI commands to check work
Check node version
node --version
Check node install location
which node
Use Alsias to switch Node versions
Add and alias to .zshrc
for each Node version installed.
Copy the following to .zshrc
alias node16='export PATH="/usr/local/opt/node@16/bin:$PATH"'alias node14='export PATH="/usr/local/opt/node@14/bin:$PATH"'
or from terminal
echo -n alias node13='export PATH="/usr/local/opt/node@16/bin:$PATH"' >> ~/.zshrcecho -n alias node13='export PATH="/usr/local/opt/node@14/bin:$PATH"' >> ~/.zshrc
Refernece alias in CLI to switch between node versions
Example
node16node -v # v16.11.0
📔 This solution only changes the Node version in the terminal instance