Skip to content

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.

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

Install default versions of node and package managers which are used when there are no package managers.

Terminal window
volta install node@20
volta install yarn@1
volta 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:

Terminal window
volta pin node
volta 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.

Terminal window
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.

~/.config/fish/conf.d/fnm.fish
fnm env --use-on-cd | source

Add the --corepack-enabled option to use corepack to manage package managers like pnpm and yarn.

~/.config/fish/conf.d/fnm.fish
fnm env --use-on-cd --corepack-enabled | source

See other fnm options here.

Add fish auto complete.

Terminal window
touch ~/.config/fish/completions/fnm.fish
fnm 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#

Terminal window
brew install mise
mise settings set experimental true
mise use -g node@22
mise use -g npm:@antfu/ni

Enable Corepack.

~/.config/mise/config.toml
[tools]
node = "22"
"npm:@antfu/ni" = "latest"
[settings]
experimental = true
[env]
MISE_NODE_COREPACK = 'true'

Verify that it is working.

Terminal window
mise doctor

Usage#

Can read the required node version from .nvmrc and .node-version.

Terminal window
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.