I've been using nvm for quite a long time to manage the different Node versions on my machine. nvm immediately remains me of the time when I was using RVM (Ruby Version Manager).
Apart from a great name and massive usage, nvm has some issues that can be easily fixed with a “more modern” alternative.
I’ve recently started using Volta and it does have many advantages in comparison with nvm.
First of all, it’s really fast (Volta claims to be ~40x faster than NVM). Switching to different versions or installing new Node/NPM versions has been a real pleasure. The startup time and project version switching are considerably fast.
Second, it always loads the correct Node version you need between your projects, whereas nvm doesn’t do it by default. With nvm, each time you switch to a different project that runs a different Node version than the default one, you need to either run nvm use <NODE_VERSION_NUMBER>
or by locking a node version in a .nvmrc
for each of your projects. Furthermore, you will still need to have a loaded script setup in your bash profile terminal that automatically searches for a .nvmrc
and updates the node version when needed. In addition, there is always a delay when switching to another version with nvm (Volta switches the Node version instantly).
Volta (and a few other package managers like pnpm
) does this under the hood. That way, when you are dealing with multiple repositories using different node versions, you won’t have any bad surprises of updating some dependencies with the wrong node version for instance.
For instance, volta pin node@14
will store your pinned version in your package.json
of your project.
"volta": {
"node": "14.21.2"
}
Each time you go to one of your projects, Volta will read your package.json
file and automatically and instantly set the relevant NodeJS version that reflects with what was pinned. You can also (and very easily) install a specific Node version with the following through Volta volta install node@16
.
Volta also allows you to install and pin globally your favorite package manager. e.g. volta install yarn && volta pin yarn@3
for Yarn berry v3.
package.json
...
"volta": {
"node": "18.17.1",
"yarn": "3.6.1"
}
...
It's also good to mention that Volta supports the same .nvmrc
config file as nvm.
Global libraries
With Volta, the packages installed globally on your machine are associated with the correct Node version that installed them, so we are sure we use the stable packages that work on the current running Node version.
Windows support
Finally, although you might not need this, it’s nice to mention that Volta is also available on Windows, whereas nvm is only available on Mac/Linux machines.