Skip to main content
StackDevLife
Node.jsbeginnerJune 12, 2026

NVM Cheatsheet

Every nvm (Node Version Manager) command you need — installing, switching, and managing Node.js versions, aliases, .nvmrc workflows, and troubleshooting.

Installation & Setup

Install nvm (curl)

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

Installs into ~/.nvm and adds the loader snippet to your shell profile (.bashrc / .zshrc).

Install nvm (wget)

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

Load nvm in your shell profile

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Add to ~/.zshrc or ~/.bashrc if the installer didn't. Restart the terminal afterwards.

Verify installation

command -v nvm   # prints "nvm" if installed
nvm --version

Use `command -v nvm`, not `which nvm` — nvm is a shell function, not a binary.

Show all commands

nvm --help

Installing Node Versions

Install latest Node.js

nvm install node

"node" is an alias for the latest available version.

Install latest LTS

nvm install --lts

Install a specific version

nvm install 22          # latest 22.x
nvm install 20.11.1     # exact version
nvm install lts/iron    # LTS by codename (Node 20)

Install + migrate global packages

nvm install 22 --reinstall-packages-from=20

Installs the new version and reinstalls global npm packages from the old one.

Uninstall a version

nvm uninstall 18.19.0

You can't uninstall the currently active version — switch first with `nvm use`.

Switching & Running Versions

Switch version (current shell)

nvm use 22
nvm use --lts
nvm use node    # latest installed

Only affects the current terminal session.

Show active version

nvm current
# or
node -v

Run a script with a specific version

nvm run 20 app.js

Runs without switching the shell's active version.

Run any command with a specific version

nvm exec 20 npm test

Spawns a subshell with that version — great for one-off commands.

Show path to a version's binary

nvm which 22

Deactivate nvm in this shell

nvm deactivate

Restores the system Node.js (if any) for the current session.

Listing Versions

List installed versions

nvm ls

The arrow marks the active version; aliases like default are shown too.

List all available versions

nvm ls-remote

List available LTS versions only

nvm ls-remote --lts

Resolve newest matching version

nvm version-remote 22     # newest 22.x available
nvm version 20            # newest 20.x installed locally

Default Version & Aliases

Set the default version (new shells)

nvm alias default 22
nvm alias default lts/*   # always newest installed LTS
nvm alias default node    # always newest installed

The default alias is what new terminal sessions start with.

Create a custom alias

nvm alias work 20.11.1
nvm use work

List all aliases

nvm alias

Delete an alias

nvm unalias work

.nvmrc & Per-Project Versions

Pin a version for a project

echo "22" > .nvmrc
# or pin exactly:
node -v > .nvmrc

Commit .nvmrc so everyone on the team uses the same Node version.

Use the project's pinned version

nvm use      # reads .nvmrc in current dir (or parents)
nvm install  # installs the .nvmrc version if missing

Auto-switch on cd (zsh)

# add to ~/.zshrc after the nvm loader:
autoload -U add-zsh-hook
load-nvmrc() {
  if [[ -f .nvmrc ]]; then nvm use --silent; fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc

Switches Node automatically whenever you cd into a directory with a .nvmrc.

Maintenance & Troubleshooting

Copy global packages between versions

nvm reinstall-packages 20

Reinstalls the global packages from version 20 into the currently active version.

Clear the download cache

nvm cache clear
nvm cache dir    # show cache location

Upgrade nvm itself

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

Re-running the installer updates nvm in place — installed Node versions are kept.

Fix slow shell startup

# load nvm lazily / skip .nvmrc lookup:
nvm use --silent
# or set default without io.js/legacy checks:
export NVM_LAZY_LOAD=true   # (with zsh-nvm plugin)

nvm adds ~100-500ms to shell startup; lazy-loading plugins avoid it.

Uninstall nvm completely

rm -rf "$NVM_DIR"
# then remove the nvm lines from ~/.zshrc or ~/.bashrc
#nvm#node-versions#version-manager#cli