Volta: A Better Node.js Version Manager Than NVM

You may want to read this article in Bahasa Indonesia version: Volta: Cara Mengganti Versi Node.js yang Lebih Baik dari NVM

The Complexity of Versions in Node.js

Node.js is a JavaScript runtime that has grown incredibly fast. As a consequence, there are now many versions of Node.js available. If we look at Node.js’ release schedule, we can see that it has numerous versions, unlike other programming languages that tend to be more stable and have a longer release cycle for new versions. Since its release in 2009, Node.js has already seen 22 major versions, with a new release every six months.

Node.js Release Schedule as of September 2024
Node.js Release Schedule as of September 2024

NVM vs Volta

Therefore, NVM (Node Version Manager) has been used by Node.js developers for a long time to manage multiple versions of Node.js. Its ability to quickly switch between different Node.js versions has made it a go-to choice, especially when working on projects that require different Node.js versions.

NVM GitHub Repository (Source: https://github.com/nvm-sh/nvm)
NVM GitHub Repository (Source: https://github.com/nvm-sh/nvm)

Although NVM is currently the most commonly used tool, many developers may not be aware that there is another tool that can serve as a faster and more efficient alternative. This tool has become my personal choice for managing Node.js versions on my local environment. The name of the tool is Volta.

Volta - The Hassle-Free JavaScript Tool Manager (Sumber: https://volta.sh)
Volta - The Hassle-Free JavaScript Tool Manager (Sumber: https://volta.sh)

The key advantage of Volta over NVM, which is a highlight nowadays, is its ability to automatically switch Node.js versions per project. This is different from NVM, which still requires a few commands even if the Node.js version has already been set using a .nvmrc file. Some of the other key benefits of Volta compared to NVM include:

  • Faster switching between Node.js versions.
  • Global package manager management such as NPM, Yarn, PNPM, etc.
  • Compatibility with various OS platforms like Windows, Linux, macOS, and others.
  • Seamless version switching between projects, just by configuring package.json in each project.

Installing Volta

For Windows, the recommended way to install Volta is by using winget.

bash

winget install Volta.Volta

For Linux and other Unix-based OS, Volta can be installed using curl.

bash

curl https://get.volta.sh | bash

For macOS, Volta can be installed using Homebrew.

bash

brew install volta

The full installation guide can be found on the official website at .

Node.js Version Setup with Volta

Volta manages Node.js versions in two ways: globally and per project. Each can be configured separately without interfering with one another.

To change the Node.js version globally, you can use the command below.

bash

volta install node@22.5.1

Volta will set Node.js version 22.5.1 as the default version on your computer. Volta will always use this default version unless the terminal is inside a project directory with a Volta configuration specifying a different Node.js version.

The Node.js version in volta install can also be written more generally, and you can even use options like latest for the latest Node.js version or lts for the latest Long-Term Support (LTS) version of Node.js.

bash

volta install node@22
volta install node@latest
volta install node@lts

To use a different Node.js version for each project, you can run the volta pin command as follows:

bash

volta pin node@20.16
volta pin yarn@1.19

Alternatively, you can manually add the volta property in the project’s package.json. This allows you to save the specific Node.js version and commit this configuration to version control systems like Git.

package.json

"volta": {
  "node": "20.16.0",
  "yarn": "1.19.2"
}

With this setup, you no longer need to manually switch Node.js versions when entering a project through the terminal. Volta will automatically adjust the Node.js version based on the configuration saved in the package.json.

bash

node --version # 20.16.0
yarn --version # 1.19.2

For more detailed information, you can check out the guide at .

Conclusion

While NVM is still a popular solution for managing Node.js versions, it’s worth considering alternatives like Volta. Its key advantages, such as automatic Node.js version switching per project, make it a great choice for developers working on multiple projects. What do you think? Feel free to share your thoughts in the comments section. Thank you!


Source

Related Content