DEV Community

Lyumo
Lyumo

Posted on

Multiple Node.js versions - setup memo

While a lot of times, installing the latest version of Node.js via preferred package manager is enough, in some cases more flexibility is needed.
For example, sometimes there are several projects to work on, each of which relies on a specific Node.js version.

This blog post presents an overview of Node.js setup to support the above scenario.

There are two commonly used tools for managing multiple Node.js versions - nvm and n.
In this post, we will use nvm.

Using nvm (Node Version Manager)

nvm, or Node Version Manager, is a solution provided by Node.js team themselves. It is an open source with straightforward installation and usage flow.

Install with the package manager of your choice. For macOS, I will use Homebrew:

brew install nvm 
Enter fullscreen mode Exit fullscreen mode

Next, let's check available Node.js versions:

nvm ls-remote 
Enter fullscreen mode Exit fullscreen mode

Let's install the first version:

nvm install <version> # Replace <version> with the desired version, e.g., 18.16.0 
Enter fullscreen mode Exit fullscreen mode

Installed versions could be checked with:

nvm ls 
Enter fullscreen mode Exit fullscreen mode

To switch between versions:

nvm use <version> # Replace <version> with the desired version 
Enter fullscreen mode Exit fullscreen mode

With that, the setup of multiple Node.js versions has been completed.

It is also possible to set the version as default one with nvm alias default <version>.
See this answer for more details.
Finally, check the version with node --version command.

Resources

Top comments (0)