Switching Node.js Versions on a MacBook

Switching Node.js Versions on a MacBook Pro Using NVM

Navigating different Node.js versions can be a challenge, especially when managing various projects. Enter the Node Version Manager (NVM), the go-to solution for seamless Node.js version management on a MacBook Pro. This guide walks you through the steps to effortlessly switch between Node.js versions using NVM.


Checking if NVM is Installed:

Begin by determining whether NVM is already set up on your device. Simply input the command below in your terminal:

command -v nvm

Should NVM be installed, the command will return nvm. If not, consider installing NVM first.


Installing a Specific Version of Node.js:

To install a desired Node.js version, use the nvm install command:

nvm install 14.21.0

NVM will promptly retrieve and install your specified version.


Switching Between Node.js Versions:

To alter the Node.js version for the current session:

nvm use 14.21.0

Your terminal will then adopt the chosen Node.js version.


Setting a Default Node.js Version System-Wide:

For a preferred Node.js version across all sessions:

nvm alias default 14.21.0

This ensures every new terminal session, irrespective of directory or project, defaults to using Node.js version 14.21.0.


Specifying a Node.js Version for a Particular Project:

For a project-specific Node.js version:

Navigate to your project directory.
Create a .nvmrc file:

echo "14.21.0" > .nvmrc

In the project directory, input:

nvm use

This confines the Node.js version to the one outlined in the .nvmrc file for that specific project directory. Remember to run nvm use each time you access the project directory or initiate a fresh terminal session there.


Embrace the convenience of NVM and enhance your development workflow. Juggle between Node.js versions with ease, ensuring optimal compatibility across your projects for a smoother development journey.