banner
Lainbo

Lainbo's Blog

github

Using Volta

This is a tool that can automatically use the corresponding node version based on the project, without the need to switch versions with nvm every time.

That is, there is no need to switch node versions between multiple projects without any awareness.

Download#

Download link

Installation#

The recommended installation method by the official is

Note

Volta's functionality depends on creating symbolic links, so you must:

  • Enable Developer Mode (recommended)
  • Run Volta with elevated privileges (not recommended)

Specify a default node version to use#

The following commands all work

If not installed, it will execute the download and installation. If the corresponding version is already installed, these statements are considered as switching the default node version

# Latest version, omit version or write node@latest
volta install node

# Specify major version, all subsequent operations specifying major versions like this will make Volta find a version it deems appropriate
volta install node@18

# Specify exact version
volta install node@12.22.10

If there is a download failure, we can manually download it#

By visiting Ali's node mirror, find the version you want and click on it

Download the package for Windows if you are using Windows, darwin for Mac-Intel, and arm for Mac-ARM

After downloading, on Windows, it is usually placed in C:\Users\Username\AppData\Local\Volta\tools\image\node

image

View current environment information#

The volta list command can check the installed Node runtimes, package managers, and packages with binary files.

volta list
volta list all

Go to the project#

For example, if I have a project A that needs to use node12 version to work properly, then I should open the command line in project A

Execute

volta pin node@12.22.10
volta pin yarn@1

# Of course, you can specify volta pin node@12 without precision. Volta will switch/download to a version it deems appropriate, but it is not recommended because this may result in downloading many different versions of node12 (in this example, node) in the computer

At this time, the project package.json will have an additional configuration. For those who do not have volta installed, this configuration has no effect. For those who have installed volta, this configuration will guide how volta works on the computer

"volta": {
  "node": "12.22.10"
}

Using pnpm#

pnpm is currently in the experimental stage. To enable it, make sure to set the VOLTA_FEATURE_PNPM environment variable to 1. On Windows, you can add it to the user or system environment variables in the system settings. On Linux/Mac, you can set the value in configuration file scripts (such as .bash_profile, .zshrc, or similar).
Due to this support being experimental, pnpm is not supported temporarily.

Global installation#

For example, pnpm install -g will result in an error.

Migration#

There is currently no automatic migration feature, so if you previously had pnpm installed globally with Volta, you will need to reinstall it manually by calling volta install pnpm. Before enabling support and reinstalling, you can uninstall previously installed packages by calling volta uninstall pnpm. Once switched to native pnpm support, you may not be able to remove isolated old packages by calling the same command, as there is currently a lack of uninstallation implementation.

Conclusion#

These are some basic operations to use Volta. For more advanced operations, you can refer to the Volta documentation.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.