Switch Node.js version with nvm

Low risk
What do risk levels mean?
Read-only
Inspects state without changing anything.
Low risk
Reversible with a routine follow-up command.
Medium risk
Changes state; undo path documented.
Destructive
Deletes or overwrites; confirmation required.

Installs (if needed) and activates a specific Node.js version using nvm, so the shell matches the version a project expects.

nodenvmversion

Parameters

Node.js version to activate, e.g. 22 or 20.11.1.

Commands

List Node.js versions already installed by nvm

nvm ls

Install the requested version if it is not present

nvm install "22"

Activate the requested version in the current shell

nvm use "22"

Verification

node --version

The printed version matches the requested one.

Undo

Switch back to the default Node.js version

nvm use default

Pitfalls

  • nvm activation is per-shell on macOS/Linux; new terminals revert to the default unless you run nvm alias default.
  • nvm-windows switches the version system-wide, affecting all open terminals.
  • Global npm packages are per Node.js version and are not carried over when switching.

Related