Getting Started with Node Version Manager (NVM) on Mac
First make sure you have Homebrew installed. If not then follow the instructions on the Homebrew website.
If it is installed then run:
brew updateOnce this has finished then run:
brew install nvmOnce this has completed there were some caveats in the outlined in the terminal.
You should create NVM's working directory if it doesn't exist:
mkdir ~/.nvm
Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completionNVM does work for the current session but if you restart the machine or start a terminal in another program such as VS Code then it won't work. In order to avoid this I needed to add following to the .profile and .zshrc files in the user (~) directory.
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completionTo check the version of NVM installed run:
nvm -vTo check the version of node installed use:
node -vTo install the latest version of Node.js run:
nvm install --ltsWhen the install is finished then version of Node what was installed becomes the active version.
To install a specific version of Node use:
nvm install 18 # install the most recent version of Node.js 18
nvm install 18.18.0 # install a more specific version of NodeTo change the active version of Node use:
node -v
~ % v20.8.0
nvm use 18 # to change to Node.js version to 18.
~ % Now using node v18.8.0 (npm v9.8.1)
node -v
~ % v18.8.0You can now easily switch between Node versions depending on your needs. This also updates the version of NPM being used.
Comments ()