DEV Community

Andreas Bergström
Andreas Bergström

Posted on • Updated on

Easily switch between multiple Node versions without using nvm

Switching between different versions of Node.js can be a crucial task for developers, especially when working on multiple projects that have different requirements. Typically, the easiest way to manage multiple versions of Node.js is to use a version manager like nvm (Node Version Manager). However, there is another way to switch between Node.js versions without using nvm, and that is by using Homebrew and the link and unlink commands.

Homebrew is a popular package manager for macOS, which allows you to easily install, update and manage various packages and applications. By installing Node.js with Homebrew, you can easily switch between different versions using the link and unlink commands.

Here's how to switch between Node.js versions without nvm:

Step 1: Install Homebrew

If you haven't already installed Homebrew on your macOS system, you can do so by running the following command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

This command will install Homebrew on your system.

Step 2: Install Node.js with Homebrew

Once you have installed Homebrew, you can use it to install Node.js by running the following command in your terminal:

brew install node
Enter fullscreen mode Exit fullscreen mode

This command will install the latest version of Node.js available in Homebrew.

Step 3: Check the installed version of Node.js

After installing Node.js, you can check the version of Node.js by running the following command in your terminal:

node -v
Enter fullscreen mode Exit fullscreen mode

This command will display the currently installed version of Node.js.

Step 4: Install another version of Node.js

If you want to install a different version of Node.js, you can do so using Homebrew. For example, if you want to install Node.js version 14, you can run the following command in your terminal:

brew install node@14
Enter fullscreen mode Exit fullscreen mode

This command will install Node.js version 14.

Step 5: Switch between Node.js versions

To switch between Node.js versions, you need to use the link and unlink commands provided by Homebrew. First, you need to unlink the current version of Node.js by running the following command in your terminal:

brew unlink node
Enter fullscreen mode Exit fullscreen mode

This command will unlink the current version of Node.js.

Next, you need to link the desired version of Node.js by running the following command in your terminal:

brew link node@14
Enter fullscreen mode Exit fullscreen mode

This command will link Node.js version 14. Now, when you run the node -v command, it should display version 14.

To switch back to the latest version of Node.js, you can simply unlink the current version and link the latest version by running the following commands in your terminal:

brew unlink node@14
brew link node
Enter fullscreen mode Exit fullscreen mode

This will switch back to the latest version of Node.js installed by Homebrew.

In conclusion, using Homebrew and the link and unlink commands is a simple and effective way to switch between different versions of Node.js without the need for a version manager like nvm. This method is especially useful for developers who prefer not to use a version manager or who are not familiar with it.

Top comments (0)