NodeJSVersion Management with nvm

Version Management with nvm

Real-world developers juggle multiple projects, and those projects often require different Node.js versions. A version manager lets you install many versions side by side and switch between them per project — no sudo, no conflicts, no broken system packages. The most popular on macOS/Linux is nvm (Node Version Manager).

How nvm actually works

nvm is not a binary — it is a shell function sourced into your .bashrc/.zshrc. When you run nvm use 20, it simply rewrites your PATH so that ~/.nvm/versions/node/v20.../bin comes first. That is why it needs no sudo (everything lives in your home directory) and why it only affects the current shell:

What 'nvm use' changes

Text
~/.nvm/versions/node/
   ├─ v18.20.0/bin/node
   ├─ v20.11.0/bin/node   ← 'nvm use 20' puts THIS dir first on PATH
   └─ v22.2.0/bin/node
Installing nvm

Bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# then restart your terminal, or:
source ~/.bashrc   # or ~/.zshrc
Windows users
Unix `nvm` does not run on native Windows — it is a bash script. Use [nvm-windows](https://github.com/coreybutler/nvm-windows) (a separate project with similar commands), `fnm`, `volta`, or run real `nvm` inside WSL2. The commands below are for Unix `nvm`.
Everyday commands

Bash
nvm install --lts        # install the latest LTS
nvm install 18           # install latest 18.x
nvm install 20.11.0      # install an exact version

nvm use 20               # switch the CURRENT shell to Node 20
nvm alias default 20     # make 20 the default in NEW shells

nvm ls                   # list installed versions
nvm ls-remote            # list everything available to install
nvm current              # show the active version
'use' is per-shell and forgotten on close
`nvm use 20` only affects the terminal you ran it in, and it resets when you open a new one. To make a version stick across new shells, set it as the default: `nvm alias default 20`. Forgetting this is the #1 nvm confusion — "why is my version back to old after reopening the terminal?"
Migrating globals when you upgrade

Each Node version has its own set of global packages — installing Node 22 does not carry over the CLIs you installed under Node 20. nvm can copy them for you:

Bash
nvm install 22 --reinstall-packages-from=20   # bring globals along
nvm install 22 --latest-npm                    # also upgrade npm
Per-project versions with .nvmrc

Drop a .nvmrc file in your project root naming the version. Teammates then run nvm use and instantly match — no guessing which Node a project expects:

.nvmrc

Bash
20.11.0

Bash
cd my-project
nvm use            # reads .nvmrc and switches automatically
Found '/my-project/.nvmrc' with version <20.11.0>
Now using node v20.11.0 (npm v10.2.4)
Switch automatically on cd
You can add a shell hook (documented in the nvm README) that runs `nvm use` whenever you `cd` into a directory containing an `.nvmrc`. Tools like `fnm` and `volta` do this automatically and faster, which is their main selling point.
Why this beats a single global install
  • Test your app against multiple Node versions before committing to an upgrade.

  • Match each project to the version it was built for — no "works on my machine" surprises.

  • Upgrade or roll back in seconds without touching system files or using sudo.

  • CI can read the same .nvmrc, so local and pipeline use identical versions.

Alternatives

Tool

Why pick it

fnm

Rust-based, very fast, auto-switches on cd, cross-platform

Volta

Pins tool versions per project via package.json; works on Windows

asdf / mise

One manager for many languages (Node, Python, Ruby…)

corepack

Not a Node manager — manages yarn/pnpm versions instead

Next
Understand which versions to actually install in [LTS vs Current Releases](/nodejs/nodejs-versions).