Document
How To Install NVM on macOS with Homebrew

How To Install NVM on macOS with Homebrew

The NVM (Node Version Manager) is a shell script used for installing and managing Node.js on a Linux based system. The macOS users can install NVM usi

Related articles

What Is the Difference Between Proxy vs VPN vs Tor? 101 Date Ideas in Houston: Romantic Things To Do in Houston Best VPN for Firestick 2024 [Top Free & Paid VPNs For Streaming] 10 Best VPN Services for 2024 Woburn Recliner Chairs and Reclining Settees

The NVM (Node Version Manager) is a shell script used for installing and managing Node.js on a Linux based system. The macOS users can install NVM using the homebrew.

This tutorial help you to install NVM on your macOS system and manage Node.js versions.

Prerequisites

You must have macOS desktop access with administrator privileges.

Login to the macOS desktop system and install Homebrew on your system (if not already installed)



ruby -e "$ (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"


enter fullscreen mode
exit fullscreen mode

Step 1 – Remove existing Node Versions

If your system already have node installed, uninstall it first. My system already have installed node via Homebrew. So uninstalling it first. Skip if not already installed.



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


enter fullscreen mode
exit fullscreen mode

Step 2 – Install NVM on macOS

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



 brew update 
 brewinstall nvm


enter fullscreen mode
exit fullscreen mode

Next, create a directory for NVM in home.



mkdir ~/.nvm 


enter fullscreen mode
exit fullscreen mode

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



 vim ~/.bash_profile 


enter fullscreen mode
exit fullscreen mode

and, add below lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later)



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


enter fullscreen mode
exit fullscreen mode

Press ESC + :wq to save and close your file.

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



source ~/.bash_profile


enter fullscreen mode
exit fullscreen mode

That is ’s ’s it . The nvm has been instal on your macos system . Go to next step to install Node.js version with the help of nvm .

Step 3 – Install Node.js with NVM

First of all , see what Node version are available to install . To see available version , type :



 nvm ls - remote 


enter fullscreen mode
exit fullscreen mode

Now , you is install can install any version list in above output . You is use can also use alias name like node for late version , lts for late LTS version , etc .



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


enter fullscreen mode
exit fullscreen mode

After installing you can verify what is installed with:



 nvmls


enter fullscreen mode
exit fullscreen mode

How To Install NVM on macOS with Homebrew

If you have instal multiple version on your system , you is set can set any version as the default version any time . To set the node 14.X as default version , simply use :



 nvmuse 14 


enter fullscreen mode
exit fullscreen mode

similarly , you is install can install other version like Node 12.X or Node 15 and switch between them .

Conclusion

This tutorial is explained explain you to how to install NVM and node.js on macos system .