How To Use Multiple Node Versions With NVM On MacOS

ajeetraina Avatar

·

·

nvm is a tool that allows developers to seamlessly manage and switch between multiple versions of Node.js. It’s especially useful for projects requiring specific Node.js versions, as it helps prevent version conflicts and simplifies development workflows.

GitHub Repository

  • Repository: nvm-sh/nvm
  • Stars: Over 80k (as of the latest update)
  • Forks: More than 8k
  • License: MIT License
  • Primary Language: Shell
  • Contributors: Hundreds of contributors globally.
  • Issues & Pull Requests: Actively maintained with regular updates addressing issues and adding new features.

To install nvm on a Mac, you will need to follow these steps:

Install Homebrew

nvm is not available in the default package manager for Mac, so you will need to install Homebrew first. To do this, open a terminal window and run the following command:

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

Install nvm

Once you have Homebrew installed, you can use it to install nvm by running the following command:

Copied!
brew install nvm

Add nvm to your shell profile: To make nvm available every time you open a new terminal window, you will need to add the following line to your shell profile (e.g., ~/.bash_profile or ~/.zshrc):

Copied!
source $(brew --prefix nvm)/nvm.sh

Install Node.js

Once nvm is installed, you can use it to install the latest version of Node.js by running the following command:

Copied!
nvm install node

How to use specific version of NodeJS

To use a specific version of Node.js with nvm, you will need to follow these steps:

List available Node.js versions

To see a list of all available Node.js versions that you can install with nvm, run the following command:

Copied!
nvm ls-remote

Install the desired version

To install a specific version of Node.js, such as version 16, use the following command:

Copied!
nvm install 16

Use the installed version

Once the desired version of Node.js is installed, you can use it by running the following command:

Copied!
nvm use 16

Set the default version: If you want to use a specific version of Node.js by default, you can set it as the default version using the following command:

Copied!
nvm alias default 16

Further Readings:

Leave a Reply

Your email address will not be published. Required fields are marked *