Open up a new Terminal and run the following to install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Create a .zshrc file in Macintosh HD -> Users -> {{your user folder}} if you don't have one already (or .bash_profile, .profile, or .bashrc if you're not using zsh) and add the following lines to load and automatically run nvm when opening a new Ternimal:
# Load nvm
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Add the lines below if you'd like nvm to be loaded automatically when you open a terminal
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
Run command -v nvm in your terminal. If nvm is returned then you have a successful installation.
Use the nvm install command to install specific Node versions on your machine (ex. nvm install 14). nvm can install more specific versions as well (ex. nvm install 14.18.3).
To set a default node version for your machine, use nvm alias default followed by the version number (ex. nvm alias default 14).
If you don't already have one, create a .nvmrc file on the root of your project and simply type the Node version number that you'd like that project to use in the file and save. This should install any new Node versions automatically, but if it doesn't just run the nvm install command followed by the version number that you'd like to use.
By adding the nvm loader to your terminal config, nvm should find and load the correct Node versions automatically, but if it doesn't or you don't want to use the automatic loader, you can use the nvm use command to load Node versions. If you have an .nvmrc file in your project, running nvm use will automatically use the version specified in the .nvmrc file, but you can also load specific versions by running nvm use followed by the version number (ex. nvm use 14).
Check the Troubleshooting on MacOS notes to ensure proper configuration. You might need to restart your Terminal windows or restart your Mac as well.
Master documentation is located on GitHub.
This worked on macOS Monterey 12.6 on a MacBook Pro (13-inch, M1, 2020)
Several other guides weren't working, so thank you very much for taking the time to share this.