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
~/.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
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash # then restart your terminal, or: source ~/.bashrc # or ~/.zshrc
Everyday commands
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
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:
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
20.11.0
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)
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 |
Volta | Pins tool versions per project via |
asdf / mise | One manager for many languages (Node, Python, Ruby…) |
corepack | Not a Node manager — manages |