nvm.fish
A Node version manager for Fish.
Different projects need different versions of Node. nvm.fish installs and switches between them, shell by shell, so you can sail from project to project without touching your system’s Node.
nvm.fish is written from scratch in Fish. You don’t need nvm.sh or Bash to use it.
- Completes commands and versions with Tab
- Reads
.nvmrc and .node-version files
- Follows the XDG Base Directory spec
- Needs no setup
Installation
nvm.fish needs Fish 3.2 or newer. Install it with Fisher:
fisher install jorgebucaran/nvm.fish
Using nvm.fish
Installing versions
nvm install downloads a Node version and switches to it.
nvm install lts
lts is the newest version with long-term support. Each LTS release line has a codename too, like jod for Node 22. The codename means the newest version in that line.
nvm install jod
latest is the newest version of Node, LTS or not.
You can also give a version number. A partial number like 22 means the newest 22.x.x version, and a full number like 22.11.0 means that version exactly. A v in front is optional.
nvm install 22
If you already have the version, nvm install switches to it without downloading it again.
Node also publishes alpha versions, early builds of the next major version. nvm install alpha installs the newest alpha version. latest and version numbers skip alpha versions, unless you set nvm_alpha.
Switching versions
nvm use switches the current shell to a version you have installed.
nvm use 22
nvm use system switches to your system’s Node, if you have one. That’s the Node you installed without nvm.fish. nvm deactivate removes the version in use from PATH, so node runs your system’s Node if you have one. nvm current prints the version in use.
$ nvm current
v22.23.5
Listing versions
nvm list shows the versions you have installed, oldest first. ▶ marks the version in use, and system is your system’s Node.
$ nvm list
system
v20.20.2 lts/iron
▶ v22.23.5 lts/jod
v24.22.3 lts/krypton
nvm list-remote shows every version you can install, and ✓ marks the versions you have. Both commands take a regular expression to filter the list.
nvm list-remote jod
Uninstalling versions
nvm uninstall deletes a version you have installed.
nvm uninstall 20
Exit status
If a command works, nvm.fish exits with status 0. If a command fails, like when a version isn’t installed, nvm.fish exits with status 1. If the command line is wrong, like an unknown command, or nvm use with no version and no .nvmrc file, nvm.fish exits with status 2.
The .nvmrc file
To pin a project to a Node version, write the version in an .nvmrc file at the root of your project. The file can also hold a name, like lts or jod. nvm.fish reads .node-version files too.
node --version >.nvmrc
Then run nvm install or nvm use without a version, from anywhere in the project. nvm.fish looks for the file in the current directory and then in each parent directory, until it finds one.
Switching versions automatically
nvm.fish doesn’t switch versions when you change directories. To switch each time you cd into a project, save this function in ~/.config/fish/conf.d/nvm_auto_use.fish and open a new shell:
function nvm_auto_use --on-variable PWD
nvm use 2>/dev/null
end
nvm_auto_use
Fish runs the function each time you change directories. nvm use switches to the version in the nearest .nvmrc file. If there’s no .nvmrc file, or if the project’s version isn’t installed, the shell keeps its version and 2>/dev/null hides the error. nvm_auto_use at the end runs the function when the shell starts, so a shell that opens inside a project switches too.
Variables
These variables change how nvm.fish works. Set them with set --universal, so new shells see them.
nvm_default_version
The version that new shells switch to. nvm use default switches to it in a shell that’s already running.
set --universal nvm_default_version lts
New shells switch to this version before Fish reads config.fish, so set it at the prompt instead. If you change nvm_data, set it at the prompt too, because new shells need it to find the default version.
nvm_default_packages
npm packages to install globally each time nvm install switches to a version.
set --universal nvm_default_packages pnpm typescript
nvm_data
Where nvm.fish keeps Node versions. The default is $XDG_DATA_HOME/nvm, which is ~/.local/share/nvm if XDG_DATA_HOME isn’t set.
nvm_mirror
Where nvm.fish downloads Node from. The default is https://nodejs.org/dist.
nvm_arch
The architecture in the name of the file that nvm.fish downloads, like x64 in node-v22.23.5-linux-x64.tar.gz. nvm.fish works out the architecture of your machine, so you only need nvm_arch for a different build. For example, Alpine Linux needs the musl builds of Node, which Node publishes on its unofficial builds site:
set --universal nvm_mirror https://unofficial-builds.nodejs.org/download/release
set --universal nvm_arch x64-musl
nvm_alpha
Set nvm_alpha to include alpha versions in latest and in version numbers like 27. nvm install 27.0.0 still installs the real 27.0.0, never an alpha version.
set --universal nvm_alpha
License
MIT
评论