How To Install NVM on macOS with Homebrew
We are going to go through NVM - Node Version Manager and how to setup via Homebrew
The NVM (Node Version Manager) is a shell script that is used to install and manage Node.js on a Linux-based system. Homebrew is used to install NVM on macOS.
This guide will show you how to install NVM on your macOS machine and manage
- Install Homebrew (You must have admin privileges)
Step 1 – Remove existing Node Versions
If your system already has a node installed, uninstall it first. My system already has installed node via Homebrew. So uninstalling it first. Skip if not already installed.
Step 2 – Install NVM on macOS
Update the Homebrew package list and install NVM.
Next, create a directory for NVM at home.
Now, configure the required environment variables. Edit the following configuration file in your home directory
and, add the below lines to ~/.bash_profile
Save and close the window
Next, load the variable to the current shell environment. From the next login, it will automatically loaded.
That's all. Your macOS system now has the NVM installed. Continue to the following step to install Node.js versions using nvm.
Step 3 – Install Node.js with NVM
First, let's see what Node versions are available to install. By typing:
Now, you can install any version listed in the above output. You can also use aliases names like node for the latest version, lts for latest LTS version, etc.
After installing you can verify what is installed with:
If you have installed multiple versions on your system, you can set any version as the default version at any time. To set node 14.X as the default version, simply use:
Similarly, you can install other versions like Node 12, 15, and 18 versions and switch between them.