iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article

Volta Notes

に公開

About Volta

Volta - The Hassle-Free JavaScript Tool Manager

Built with Rust, its main features are as follows:

  1. Speed ⚡
  2. Seamless version switching per project
  3. Cross-platform support including Windows and all Unix shells
  4. Support for multiple package managers
  5. Stable tool installation - (No need to reinstall every time Node is upgraded)
  6. Extension hooks for site-specific customizations

Operating Environment

$ sw_vers
ProductName: macOS
ProductVersion: 13.3.1
ProductVersionExtra: (a)
BuildVersion: 22E772610a

Installation

I'll start the installation right away.

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

In my environment, it was installed at the following location:

$ which volta
/Users/xxxx/.volta/bin/volta
$ volta --version
1.1.1

Switching defaults like typical version management tools

First, let's try installing a version of Node we want to add.

$ volta install node@14
$ volta list all       
⚡️ User toolchain:

    Node runtimes:
        v14.21.3 (default)

    Package managers:

    Packages:

We can see that v14.21.3 has been installed. Next, let's try installing the latest version of Node.

$ volta install node
$ volta list all             
⚡️ User toolchain:

    Node runtimes:
        v14.21.3
        v18.16.0 (default)

    Package managers:

    Packages:

v18.16.0 has been installed, and (default) has also been set to v18.

To switch this back to v14.21.3, run the following:

$ volta install node@v14.21.3

Executing it like this will set the default to v14.

Pinning versions per project

The volta pin command pins the version by recording it in the project's package.json.

Therefore, if there is no package.json, an error will occur as shown below:

$ volta pin node@14.21.3
error: Not in a node package.

So, create an appropriate directory and generate a package.json.

$ mkdir sample
$ cd sample
$ yarn init

Now, let's try pinning the Node version again.

$ volta pin node@14.21.3
success: pinned node@14.21.3 (with npm@6.14.18) in package.json

You can see that a volta entry has been added to package.json.

$ cat package.json
{
  "name": "sample1",
  "packageManager": "yarn@4.0.0-rc.39",
  "volta": {
    "node": "14.21.3"
  }
}

*Note: By the way, if you try to pin npm first, an error will be displayed saying that you should pin Node first:

$ volta pin npm@9.5.0
error: Cannot pin npm because the Node version is not pinned in this project.

Use `volta pin node` to pin Node first, then pin a npm version.

How to Uninstall

Uninstalling Node with Volta

Reference URLs

【nvm】Migrating from nodebrew to nvm for Node version management & Usage

I want to recommend Volta for Node.js version management

Discussion