volta pin
The volta pin
command will update a project's package.json
file to use the selected version of a tool. It has the following syntax:
bash
Pins your project's runtime or package manager
USAGE:
volta pin [FLAGS] <tool[@version]>...
FLAGS:
--verbose Enables verbose diagnostics
--quiet Prevents unnecessary output
-h, --help Prints help information
ARGS:
<tool[@version]>... Tools to pin, like `node@lts` or `yarn@^1.14`.
Note
volta pin
only works with Node & Package Managers (e.g. npm or Yarn). For dependencies, you should usenpm install
oryarn add
to update the selected versions.
Examples
Pinning Node.js
bash
# Pin the latest LTS version of Node
volta pin node
# Pin a specific version of Node
volta pin node@16.14.2
# Pin a Node version range
volta pin node@16
When you pin a Node.js version, Volta adds a volta
section to your project's package.json
file:
json
{
"volta": {
"node": "16.14.2"
}
}
Pinning Package Managers
bash
# Pin the latest npm version
volta pin npm
# Pin a specific version of Yarn
volta pin yarn@1.22.19
# Pin pnpm (if the feature flag is enabled)
VOLTA_FEATURE_PNPM=1 volta pin pnpm@7.0.0
Pinning package managers adds them to the volta
section in your package.json
:
json
{
"volta": {
"node": "16.14.2",
"npm": "8.5.0"
}
}
Use Cases
The volta pin
command is essential for:
- Creating consistent development environments across your team
- Ensuring that everyone working on a project uses the same Node.js version and package manager
- Preventing "works on my machine" problems
- Documenting which Node.js version your project is compatible with
Effects of Pinning
When you pin a tool:
- The tool is automatically installed if you don't already have it
- The version is written to
package.json
in thevolta
section - Anyone with Volta who works on the project will automatically use the specified version
- CI/CD systems using Volta will use the correct version
Pinned tools take precedence over default tool versions set with volta install
.
Package.json Details
The volta
section in package.json
can include:
json
{
"volta": {
"node": "16.14.2", // Exact version
"npm": "^8.5.0", // Semver range
"yarn": "1.22.19", // Exact version
"pnpm": "7.0.0" // If pnpm support is enabled
}
}
The version specifiers can be:
- Exact versions:
16.14.2
- Major versions:
16
- Major.minor versions:
16.14
- Semver ranges:
^16.14.0
- Tags:
lts
,latest