Multiple Node Versions in MacOS

Node Version Manager (nvm) is a great tool to use the multiple Node version in a system.

Install Node

brew install nodejs

Check Node Version

node --version

Step - 1

Install NVM

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

Add source lines to the profile

~/.bashrc, ~/.profile, or ~/.zshrc file.

This loads nvm

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Restart terminal or Open New Terminal

Check NVM Version

nvm --version

Output:

0.39.2

Step - 2

Install Multiple Node.js Versions

  • Latest Version
nvm install node
  • Specific Version
nvm install 10.15.3
  • LTS Version
nvm install --lts
  • Set Default Version
nvm alias default 16

Step - 3

List Install Versions

nvm ls

Output:

➜  ~  nvm ls
->     v10.15.3
       v16.13.2
         system
default -> 10.15.3 (-> v10.15.3)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.13.2) (default)
stable -> 16.13 (-> v16.13.2) (default)
lts/* -> lts/gallium (-> v16.13.2)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.9 (-> N/A)
lts/fermium -> v14.18.3 (-> N/A)
lts/gallium -> v16.13.2

Step - 4

Switch Node Version

nvm use 16

Switch to Default Version

nvm use default

Step - 5

Uninstall Node Version

nvm uninstall 10

Step - 6

Uninstall NVM (Node Version Manager)

nvm unload

Step - 7 (Optional)

Set Node version in the .nvmrc file in the project’s root for specific projects
echo "16" > .nvmrc

Upgrade to the Latest NVM.

For manual upgrade with git (requires git v1.7.10+):

  1. change to the $NVM_DIR
  2. pull down the latest changes
  3. check out the latest version
  4. activate the new version
(
  cd "$NVM_DIR"
  git fetch --tags origin
  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"

Enjoy the Development!!

Explore More Technology Posts

Secure Your Web App with OAuth2 and JWT

Learn how to secure your web application using OAuth2 and JWT for robust authentication and authorization.

Read More
Understanding JWT (JSON Web Token)

Learn how JWT (JSON Web Token) works, its benefits, and real-world use cases for secure, stateless authentication in web and mobile apps.

Read More
Navigating the World of Offline UPI Payments: A Step-by-Step Guide

Learn to make UPI payments offline using USSD codes - a simple, secure way to transact without internet. Ideal for areas with poor connectivity.

Read More
ChatGPT vs. Google Bard: Which Large Language Model is Right for You?

ChatGPT and Google Bard are two powerful large language models that can be used for a variety of purposes. This blog post compares the two models and…

Read More
Download Website Source Codes: A Web Developer's Guide

Learn how to efficiently download website source codes using methods like Wget, browser extensions, and website downloader tools. Empower your web de…

Read More
What is Instagram Threads and how does it work?

Discover Threads, Meta's new microblogging app for sharing updates, photos, and engaging in public conversations. Download now!

Read More