Open
Description
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
, sovolta
has no global version of node installed. Thenvolta
will fall-through tofnm
, if you're not in a directory withvolta
inpackage.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
, afterfnm
, to make surevolta
is in your path beforefnm
-- 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 whenfnm
is actually providingnode
. 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)
Metadata
Metadata
Assignees
Labels
No labels