The open blogging platform. Say no to algorithms and paywalls.

How to install NVM on a Mac

macOS users can use homebrew to install NVM. This tutorial helps you install NVM and manage Nodej.is the version on macOS systems. If the node is already installed on your system, please uninstall it…

macOS users can use homebrew to install NVM. This tutorial helps you install NVM and manage Nodej.is the version on macOS systems.

Prerequisites Install homebrew on macOS using

/bin/bash -c "$(curl -fsSL https:/raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 1: Remove the existing Node version

If the node is already installed on your system, please uninstall it first. My system already has a node installed via Homebrew. So uninstall it first. Skip if installed later.

brew uninstall --ignore-dependencies node
brew uninstall --force node

Step 2: Install NVM on Mac

Now, your system is ready for installation. Update the Homebrew package list and install NVM.

brew update
brew install nvm

Next, create a folder for NVM in your home directory.

mkdir ~/.nvm

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

vim ~/.bash_profile

Then, add the following lines to your ~/.bash_profile (or ~/.zshrc for macOS Catalina or later)

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

Press ESC + :wq to save and close your file. Next, load that variable into the current shell environment. On the next login, it will be loaded automatically.

source ~/.bash_profile

NVM is already installed on your macOS system. Next, install the version of Node.js you need with the help of nvm.

Step 3: Install Node.js with NVM

First, see what versions of Node are available for installation. To see available versions, enter.

nvm ls-remote

Now, you can install any version listed in the above output. You can also use aliases like node for the latest release, lts for the latest LTS release, etc.

nvm install node ## Install the last long-term support release
nvm install 10

After installation, you can use the following methods to verify that the installed node.js is successfully installed.

nvm ls

The terminal command shows. screenshot by myself

If you have multiple versions installed on your system, you can set any version as the default at any time. To set node 10 as the default version, just use.

nvm use 10

Likewise, you can install other versions, like other versions of Node, and switch between them.




Continue Learning