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:
Once this has finished then run:
Once 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_completion
NVM 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.
To check the version of NVM installed run:
To check the version of node installed use:
To install the latest version of Node.js run:
When 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 Node
To 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.0
You can now easily switch between Node versions depending on your needs. This also updates the version of NPM being used.
Comments ()