nvm: install it, switch Node versions and fix common problems

Researched, not yet tested: compiled from the nvm README (v0.41.0) and source as of 30 November 2026; we couldn't run the nvm installer in our test environment. Check the commands against your setup.

nvm installs Node.js versions in your home folder and switches between them. Install it with the script from the nvm README, then install the current LTS release of Node:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash

Open a new terminal, then:

nvm install --lts
node --version

Switch versions with nvm use 22, and set the version new terminals start with using nvm alias default 22.

We couldn’t run the nvm installer in our test environment, so this page is researched from the nvm README and source code for v0.41.0, the version its install commands point to on 30 November 2026. Check the README for a newer version number before you install.

What the install script does

The README says the script clones nvm into ~/.nvm and adds these lines to your shell profile (~/.zshrc, ~/.bashrc, ~/.bash_profile, ~/.bash_login or ~/.profile):

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

It can use git, curl or wget. To pick a different profile file, set PROFILE before running the script. PROFILE=/dev/null stops it editing any file.

Check the install worked:

command -v nvm

It should print nvm. which nvm won’t work, because nvm is a shell function, not a program on your PATH.

Everyday commands

Task Command
Install the latest LTS release nvm install --lts
Install the latest release nvm install node
Install a version line or exact version nvm install 22 or nvm install 22.11.0
Switch this terminal to a version nvm use 22
Set the version new terminals use nvm alias default 22
List installed versions nvm ls
List versions you can install nvm ls-remote (add --lts for LTS only)
Run one command with another version nvm exec 20 node app.js
Show where a version’s node lives nvm which 22
Go back to Node installed outside nvm nvm use system
Remove a version nvm uninstall 20

The first version you install becomes the default. Versions like 22 resolve to the newest installed (or, for install, newest available) release in that line. lts/* means the latest LTS line and also works in commands and .nvmrc files.

To move to a new LTS release and bring your global npm packages with you, the README gives:

nvm install --reinstall-packages-from=current 'lts/*'

Pin a project’s Node version with .nvmrc

Put the version in a .nvmrc file in the project’s root:

echo "22" > .nvmrc

Then nvm use or nvm install with no version reads it. The README shows nvm use printing Found '/path/to/project/.nvmrc' with version <22.11> and Now using node v22.11.0 (npm v10.9.0). nvm looks in the current folder and then each parent folder, so it works from subfolders too. If no .nvmrc is found and you give no version, these commands exit with status 127.

The file must hold one version followed by a newline. Comments after # are allowed. If you create it from Windows Command Prompt with echo "22" > .nvmrc, the quotes end up in the file and make it invalid. To switch versions automatically when you cd into a project, the README’s deeper shell integration section has hooks for bash and zsh.

Fix “nvm: command not found”

Situation Fix (from the README)
Right after installing Close the terminal and open a new one, then command -v nvm
Mac with zsh and no ~/.zshrc touch ~/.zshrc, then run the install script again
bash with no profile file touch ~/.bashrc (or ~/.bash_profile), run the script again, then . ~/.bashrc
Installed with Homebrew brew uninstall nvm, then use the install script
In Docker or CI Non-interactive bash reads no profile. The README sets BASH_ENV to a file holding the nvm lines

For Node itself not being found after nvm install, run nvm use with the version or set nvm alias default, then open a new terminal.

nvm with npm global packages

Each Node version keeps its own global packages under ~/.nvm/versions/node/<version>. Packages you installed globally under one version aren’t there after nvm use switches to another. Reinstall them or use --reinstall-packages-from.

The README also warns that nvm isn’t compatible with npm’s prefix setting. If ~/.npmrc contains a prefix= line (a common fix for global install permission errors without nvm), remove it when you start using nvm. With nvm you don’t need sudo for npm install -g. Our npm install errors guide covers the permission errors this avoids.

Older Node versions on Apple Silicon

The README says Node added full Apple Silicon support in v16.0. For older versions it suggests installing Rosetta (softwareupdate --install-rosetta), opening a shell with arch -x86_64 zsh and installing the old version from there.

Uninstall nvm

The README’s manual steps:

nvm_dir="${NVM_DIR:-~/.nvm}"
nvm unload
rm -rf "$nvm_dir"

Then delete the nvm lines from your shell profile. This removes every Node version nvm installed. To pin Python versions per project the same way, see pyenv.

FAQ

What is nvm?

nvm (Node Version Manager) installs several versions of Node.js in your home folder and lets you switch between them per terminal or per project. It's a shell script for macOS, Linux and WSL, not a program you run from Windows Command Prompt.

Why do I get nvm: command not found?

nvm is a shell function loaded by lines the installer adds to your shell profile. Open a new terminal first. On a Mac, if ~/.zshrc didn't exist, the installer had nowhere to write: create it with touch ~/.zshrc and run the install script again. which nvm never finds it, so check with command -v nvm.

Does nvm work on Windows?

Only inside WSL, Git Bash or Cygwin, according to its README. For native Windows, the README lists separate projects such as nvm-windows, which its maintainers say they don't support or develop. nvm-windows has its own commands and behaviour.

Should I install nvm with Homebrew?

No. The nvm README says Homebrew installation isn't supported and asks people with problems to brew uninstall it and use the install script instead.

Do I need sudo for npm install -g with nvm?

No. With nvm, global packages install into the active Node version's folder under ~/.nvm, so the README says to drop sudo. Also remove any prefix line from ~/.npmrc, which nvm doesn't support.