nvm so that when I
cd into a different repo, it would automatically load the appropriate version of
npm). Simply by doing
cd ~/dev/remix-peterbecom, for example, it would make the
node executable to become whatever the value of the optional file
~/dev/remix-peterbecom/.nvmrc's content. For example
nvm helps you install and get your hands on various versions of
node to be able to switch between. Much more fine-tuned than
brew install node20.
The problem with all of this is that it's horribly slow. Opening a new terminal is annoyingly slow because that triggers the entering of a directory and
nvm slowly does what it does.
The solution is to ditch it and go for
fnm instead. Please, if you're an
nvm user, do consider making this same jump in 2024.
curl -fsSL https://fnm.vercel.app/install | bash basically does some
brew install and figuring out what shell you have and editing your shell config. By default, it put:
export PATH="/Users/peterbe/Library/Application Support/fnm:$PATH"
eval "`fnm env`"
.zshrc file. But, I later learned you need to edit the last line to:
-eval "`fnm env`"
+eval "$(fnm env --use-on-cd)"
so that it automatically activates immediately after you've
cd'ed into a directory.
If you had
direnv to do this, get rid of that.
fmn does not need
Now, create a fresh new terminal and it should be set up, including tab completion. You can test it by typing
fnm[TAB]. You'll see:
alias -- Alias a version to a common name
completions -- Print shell completions to stdout
current -- Print the current Node.js version
default -- Set a version as the default version
env -- Print and set up required environment variables for fnm
exec -- Run a command within fnm context
help -- Print this message or the help of the given subcommand(s)
install -- Install a new Node.js version
list ls -- List all locally installed Node.js versions
list-remote ls-remote -- List all remote Node.js versions
unalias -- Remove an alias definition
uninstall -- Uninstall a Node.js version
use -- Change Node.js version
If you had
.nvmrc files sprinkled about from before,
fnm will read those. If you
cd into a directory, that contains
.nvmrc, whose version
fnm hasn't installed, yet, you get this:
❯ cd ~/dev/GROCER/groce/
Can't find an installed Node version matching v16.14.2.
Do you want to install it? answer [y/N]:
But if you want to set it up from scratch, go into your directory of choice, type:
...to see what versions of
node you can install. Suppose you want
v20.10.0 in the current directory do these two commands:
fnm install v20.10.0
echo v20.10.0 > .node-version
I prefer that
.node-versionconvention so I've been going around doing
mv .nvmrc .node-versionin various projects
fnm lsis handy to see which ones you've installed already
Suppose you want to temporarily use a specific version, simply type
fnm use v16.20.2for example
I heard good things about volta too but got a bit nervous when I found out it gets involved in installing packages and not just versions of
fnmdoes not concern itself with upgrading your
nodeversions. To get the latest version of
nodev21.x, it's up to you to check
fnm ls-remoteand compare that with the output of