How to Switch Node Version on Macos

Feb 13, 2024

2 mins read

Published in

Switching Node.js Versions on macOS

Managing Node.js versions on macOS can be essential for compatibility with different projects. In this guide, we’ll explore how to switch between Node.js versions seamlessly.

Switching Node.js versions on macOS can be necessary when working on different projects that require different versions of Node.js. Thankfully, tools like nvm (Node Version Manager) make this process relatively straightforward. In this blog post, we’ll walk through the steps to install nvm, use it to install multiple Node.js versions, and switch between them as needed.

Installing nvm

First, let’s install nvm. Open your terminal and run the following command:

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

This command downloads and executes the nvm installation script. Follow the prompts, and once the installation is complete, close and reopen your terminal to start using nvm.

Installing Node.js Versions

Now that nvm is installed, let’s install the Node.js versions you need. To install a specific version, use the following command:

1
nvm install <version>

For example, to install Node.js version 14, you would run:

1
nvm install 14

You can install multiple versions by repeating this process with different version numbers.

Listing Installed Versions

To see a list of installed Node.js versions, you can use:

1
nvm ls

This will display a list of installed Node.js versions, with an indication of which version is currently in use.

Switching Node.js Versions

To switch between installed Node.js versions, you can use:

1
nvm use <version>

For example, to switch to Node.js version 14, you would run:

1
nvm use 14

Setting Default Node.js Version

If you have a preferred Node.js version that you want to use by default, you can set it using:

1
nvm alias default <version>

For example, to set Node.js version 14 as the default, you would run:

1
nvm alias default 14

In this blog post, we’ve covered how to switch Node.js versions on macOS using nvm. By following these steps, you can easily manage multiple Node.js installations and switch between them as needed for different projects. nvm simplifies the process and allows you to focus on your development work without worrying about compatibility issues with different Node.js versions.

Sharing is caring!