How To Install NVM on macOS with Homebrew
Back to Blog page

How To Install NVM on macOS with Homebrew

We are going to go through NVM - Node Version Manager and how to setup via Homebrew

Published by PJ

PJ Dec 6, 2022 2 min read

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

Prerequisites

  • Install Homebrew (You must have admin privileges)
1 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

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.

1 2 brew uninstall --ignore-dependencies node brew uninstall --force node

Step 2 – Install NVM on macOS

Update the Homebrew package list and install NVM.

1 2 brew update brew install nvm

Next, create a directory for NVM at home.

1 mkdir ~/.nvm

Now, configure the required environment variables. Edit the following configuration file in your home directory

1 open -a TextEdit ~/.bash_profile

and, add the below lines to ~/.bash_profile

1 2 export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh

Save and close the window

Next, load the variable to the current shell environment. From the next login, it will automatically loaded.

1 source ~/.bash_profile

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:

1 nvm ls-remote

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.

1 2 nvm install node ## Installing Latest version nvm install 14 ## Installing Node.js 14.X version

After installing you can verify what is installed with:

1 nvm ls

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:

1 nvm use 14

Similarly, you can install other versions like Node 12, 15, and 18 versions and switch between them.

Tagged with:
NVM
UNIX
5
0
Share
Enjoyed this article?
Leave a comment below!
Previous Article