Managing node and package manager versions
volta#
Manage the node
and package manager versions by using volta. Volta also allows you to standardise the versions of node
and the package managers used in a repository with volta’s config.
Great if you can enforce using volta
across all of the codebases you work in or you can consistently rely on a default version of node
. Not great if you need to use the version of node
specified in a .nvmrc
file.
Installation#
Install volta
.
curl https://get.volta.sh | bash
Install default versions of node and package managers which are used when there are no package managers.
volta install node@20volta install yarn@1volta install pnpm
Usage#
Inside of a repository, you can pin the node version and package manager to use in the package.json
file with the following commands:
volta pin nodevolta pin pnpm
Alternatives#
fnm#
If you need to use the version of node
specified in a .nvmrc
or .node-version
file, use fnm, a node version manager built in Rust. One of the key selling points is that it can change the version of node
when you change directories.
Installation#
Install fnm
.
curl -fsSL https://fnm.vercel.app/install | bash
Setup fish
according to these instructions. Add the --use-on-cd
option to the fnm
to change node
version when you change directories.
fnm env --use-on-cd | source
Add the --corepack-enabled
option to use corepack to manage package managers like pnpm
and yarn
.
fnm env --use-on-cd --corepack-enabled | source
See other fnm
options here.
Add fish auto complete.
touch ~/.config/fish/completions/fnm.fishfnm completions --shell fish > ~/.config/fish/completions/fnm.fish
Restart your terminal.
mise#
mise is a new up and coming “everything” version manager? See this nice breakdown on the differences between mise
and volta
.
Installation#
brew install misemise settings set experimental truemise use -g node@22mise use -g npm:@antfu/ni
Enable Corepack.
[tools]node = "22""npm:@antfu/ni" = "latest"
[settings]experimental = true
[env]MISE_NODE_COREPACK = 'true'
Verify that it is working.
mise doctor
Usage#
Can read the required node version from .nvmrc
and .node-version
.
mise missing: node@18.20.4$ mise install
nvm.fish#
nvm.fish is another performant node version manager written in Fish that respects .nvmrc
and .node-version
files. Unfortunately, it does not have native support for changing the node
version when changing directories.
Take a look at this comment to see a DIY implementation of changing the node
version when changing directories. I ran into issues with modifying the script to also install the node
version if it wasn’t already installed and jumped ship to fnm.