Managing Your Toolchain
Volta's job is to manage your JavaScript command-line tools, such as node
, npm
, yarn
, or executables shipped as part of JavaScript packages. This guide will show you how to effectively manage your toolchain with Volta.
Setting Default Tools
When you're not in a project directory, Volta uses your default tools. Setting these defaults is simple:
Installing Node.js
To install a specific version of Node.js as your default:
volta install node@16.14.2
You can also specify a major or minor version, and Volta will choose the latest matching version:
volta install node@16
Or simply install the latest LTS (Long-Term Support) version:
volta install node
Installing Package Managers
Similarly, you can set default versions of npm and Yarn:
volta install npm@8.5.0
volta install yarn@1.22.18
Or install the latest versions:
volta install npm
volta install yarn
Managing Multiple Versions
Volta makes it easy to have multiple versions of tools installed simultaneously:
Listing Installed Tools
To see all the tools in your toolchain:
volta list all
You can also list specific tool types:
volta list node
volta list npm
volta list yarn
volta list packages
Uninstalling Tools
If you no longer need a tool, you can uninstall it:
volta uninstall node
volta uninstall npm
volta uninstall yarn
volta uninstall package-name
Note that uninstalling Node doesn't remove it from Volta's cache, so projects that use that version will still work.
Working with Global Packages
One of Volta's most powerful features is its handling of global packages:
Installing Global Packages
Install packages globally using your package manager as usual:
npm install --global typescript
# or
yarn global add typescript
Volta will ensure these packages always use the right version of Node.js.
Finding Package Locations
To see where a tool is actually installed:
volta which node
volta which npm
volta which typescript
Advanced Tool Management
For more advanced use cases, Volta offers additional commands:
Fetching Without Installing
To download a tool to your local cache without setting it as default:
volta fetch node@14.17.0
volta fetch npm@7.20.3
This is useful for preparing your environment for offline work.
Running with Custom Versions
To temporarily run a command with specific tool versions:
volta run --node 14.17.0 --npm 7.20.3 node app.js
This doesn't change your defaults or project settings.
Best Practices
Here are some recommended practices for managing your toolchain:
- Set sensible defaults: Install stable LTS versions as your defaults
- Install tools globally: Take advantage of Volta's smart handling of global packages
- Keep your toolchain lean: Uninstall tools you no longer need
- Use
volta fetch
: Prepare for offline work by fetching tools in advance - Explore with
volta run
: Test different versions without changing your defaults
By effectively managing your toolchain with Volta, you can ensure a smooth and consistent development experience across all your JavaScript projects.