Installing and Configuring NVM

You can install the NVM binary with curl or using Homebrew.

Install NVM with Homebrew on macOS

brew install nvm

Install NVM Binary with Curl on macOS

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash

The above command downloads the install.sh script from the specified URL and runs it using the bash shell. When this command is executed, it will download and run the install.sh script, which will automatically install NVM on your system and configure it in your shell. This allows you to use the nvm command to manage and switch between different versions of Node.js.

Configuration

If the configuration is not done automatically, add the following lines to your shell profile file (e.g., ~/.bashrc, ~/.zshrc, or ~/.bash_profile):


    export NVM_DIR=~/.nvm
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
        

Hint: Use echo $0 to Identify Your Shell Profile

After installing NVM, restart your terminal or open a new terminal window. This is necessary for the changes made by NVM to take effect.

Usage Without Configuring the Shell Profile

If the NVM configuration is not set in your shell profile, use the following command to use NVM:

source ~/.nvm/nvm.sh

Useful Commands

Command to See the Available Versions in NVM
nvm ls
Command to Select a Specific Version in NVM
nvm use <version number>