How to install and Configure NVM on Mac OS
nvm, standing for Node Version Manager, is a versatile tool designed to enable the installation and management of various Node.js versions on your Mac. It operates as a per-user, per-shell version manager specifically tailored for node.js. nvm is compatible with any shell that adheres to POSIX standards, including sh, dash, ksh, zsh, and bash, and it runs smoothly on unix, macOS, and Windows WSL platforms.
To get nvm up and running on your Mac, you’ll need to go through the following installation process:
Setup Homebrew
Since nvm isn’t included in Mac’s default package manager, your first step involves installing Homebrew. Open a terminal window and execute the command below to get started:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Incorporate nvm into Your Shell Profile: To ensure nvm is accessible each time you launch a new terminal session, append the following line to your shell profile file (such as ~/.bash_profile or ~/.zshrc):
echo "# Homebrew\nexport PATH=/opt/homebrew/bin:\$PATH" >> .zshrc
source ~/.zshrc
Install Node.js
After setting up nvm, utilize it to install the most recent version of Node.js with this command:
brew install nvm
mkdir ~/.nvm
echo "export NVM_DIR=~/.nvm\nsource \$(brew --prefix nvm)/nvm.sh" >> .zshrc
source ~/.zshrc
Using a Specific Version of NodeJS
To select and use a particular version of Node.js via nvm, carry out the steps below:
Check Available Node.js Versions
To view the range of Node.js versions accessible for installation through nvm, execute this command:
nvm ls-remote
Install the Desired Version
To install a particular version of Node.js, for instance, version 16, employ the following command:
nvm install 16
Utilize the Installed Version
After successfully installing the preferred version of Node.js, you can activate it by executing the following command:
nvm use 16
Configure the Default Version
Should you wish to have a certain version of Node.js as your standard choice, you can make it the default by applying the following command:
nvm alias default 16