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 | bashInstalls 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 | bashLoad 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 --versionUse `command -v nvm`, not `which nvm` — nvm is a shell function, not a binary.
Show all commands
nvm --helpInstalling Node Versions
Install latest Node.js
nvm install node"node" is an alias for the latest available version.
Install latest LTS
nvm install --ltsInstall 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=20Installs the new version and reinstalls global npm packages from the old one.
Uninstall a version
nvm uninstall 18.19.0You 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 installedOnly affects the current terminal session.
Show active version
nvm current
# or
node -vRun a script with a specific version
nvm run 20 app.jsRuns without switching the shell's active version.
Run any command with a specific version
nvm exec 20 npm testSpawns a subshell with that version — great for one-off commands.
Show path to a version's binary
nvm which 22Deactivate nvm in this shell
nvm deactivateRestores the system Node.js (if any) for the current session.
Listing Versions
List installed versions
nvm lsThe arrow marks the active version; aliases like default are shown too.
List all available versions
nvm ls-remoteList available LTS versions only
nvm ls-remote --ltsResolve newest matching version
nvm version-remote 22 # newest 22.x available
nvm version 20 # newest 20.x installed locallyDefault 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 installedThe default alias is what new terminal sessions start with.
Create a custom alias
nvm alias work 20.11.1
nvm use workList all aliases
nvm aliasDelete an alias
nvm unalias work.nvmrc & Per-Project Versions
Pin a version for a project
echo "22" > .nvmrc
# or pin exactly:
node -v > .nvmrcCommit .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 missingAuto-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-nvmrcSwitches Node automatically whenever you cd into a directory with a .nvmrc.
Maintenance & Troubleshooting
Copy global packages between versions
nvm reinstall-packages 20Reinstalls the global packages from version 20 into the currently active version.
Clear the download cache
nvm cache clear
nvm cache dir # show cache locationUpgrade nvm itself
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bashRe-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