The Best Node.js Version Manager, Even Better Than NVM
Introduction to Volta
When we first started installing Node.js, we could only download the installation package from the official website to install a specific version, like 18.17.1.
But for different projects, we might need different Node.js versions, like 18.17.1 and 20.17.1.
To switch versions, you'd need to uninstall the old version, install the new one, then switch projects - extremely troublesome (pain mask).
So Node.js version managers emerged, like NVM, Volta, etc.
They support installing specific Node.js versions and allow free switching between versions.
However, NVM has some issues. For example, it can't automatically switch versions based on projects, doesn't support Windows platform (though there's an unofficial nvm-windows that works), etc.
The new generation Node.js version manager Volta solves these problems.
It can automatically switch Node.js versions based on projects and supports Mac, Windows, and Linux platforms.
Volta is built with Rust, making it faster and better.
Installing Volta
According to the installation guide, enter the following command in your terminal to install Volta:
curl -fsSL https://get.volta.sh | bash
After installation, open a new terminal and enter the following command to check the current Volta version:
volta -v
2.0.2
Congratulations, Volta is successfully installed!
Now we can use Volta to manage Node.js versions.
Enter the following command in the terminal to install Node.js:
volta install node
This command will install the latest LTS version of Node.js.
LTS: Long Term Support version.
Of course, you can also use the at symbol @
to install a specific Node.js version, for example:
volta install node@20.17.1
Project-Level Node.js Version Management
Open a Node.js project you're maintaining, like "shit-mountain", find the package.json
file, and add the following content:
{
//...
"volta": {
"node": "20.17.1"
}
}
When you run npm i
, Volta will look for Node.js version 20.17.1.
If it can't find it, Volta will automatically install Node.js 20.17.1, then execute npm i
.
This ensures the project uses Node.js version 20.17.1.
Volta has other features, like various Volta commands - list
, uninstall
, etc., as well as Hooks that can specify download sources. I won't elaborate here.
Visit the Volta website for more information 👉 https://volta.sh