If you wish to use both volta and fnm, with fnm as the default, the following setup is working so far, though I just put it together, so who knows! (details are specific to macOS / ZSH):
- Make sure you don't run
volta install node, so volta has no global version of node installed. Then volta will fall-through to fnm, if you're not in a directory with volta in package.json.
- The
volta installer adds two lines to ~/.zshenv -- leave those there so that Volta will be used by non-interactive tools, e.g. for linting.
- Copy the
volta lines from ~/.zshenv and put them in your ~/.zshrc, after fnm, to make sure volta is in your path before fnm -- in my case, that looks like the following:
eval "$(fnm env --use-on-cd)"
# Volta, copied from `.zshenv` (where it remains), to ensure it takes precedence over `fnm`
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
- One downside, especially if (when) you forget about this arrangement:
which node will return something like ~/.volta/bin/node (rather than ~/.local/state/fnm_multishells/65437_1748363068373/bin/node), even when fnm is actually providing node. You can give "future you" a clue by adding this to your ~/.zshrc:
if [[ $- == *i* && -t 1 ]]; then
autoload -U colors && colors
which() {
if [[ "$1" == "node" || "$1" == "npm" || "$1" == "yarn" || "$1" == "pnpm" ]]; then
if [[ -z "${fg[green]}" || -n "$NO_COLOR" ]]; then
echo "💡To locate the actual binary: 'volta which $1'" >&2
else
echo "💡To locate the actual binary: ${bold_color}${fg[green]}volta which $1${reset_color}" >&2
fi
fi
command which "$@"
}
fi
(I posted the same comment in the fnm repo, figured it might be useful to others)
If you wish to use both
voltaandfnm, withfnmas the default, the following setup is working so far, though I just put it together, so who knows! (details are specific to macOS / ZSH):volta install node, sovoltahas no global version of node installed. Thenvoltawill fall-through tofnm, if you're not in a directory withvoltainpackage.json.voltainstaller adds two lines to~/.zshenv-- leave those there so that Volta will be used by non-interactive tools, e.g. for linting.voltalines from~/.zshenvand put them in your~/.zshrc, afterfnm, to make surevoltais in your path beforefnm-- in my case, that looks like the following:which nodewill return something like~/.volta/bin/node(rather than~/.local/state/fnm_multishells/65437_1748363068373/bin/node), even whenfnmis actually providingnode. You can give "future you" a clue by adding this to your~/.zshrc:(I posted the same comment in the
fnmrepo, figured it might be useful to others)