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
Next, let's check available Node.js versions:
nvm ls-remote
Let's install the first version:
nvm install <version> # Replace <version> with the desired version, e.g., 18.16.0
Installed versions could be checked with:
nvm ls
To switch between versions:
nvm use <version> # Replace <version> with the desired version
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.
Top comments (0)