nvm — Manage Node.js Versions

Practical guide to nvm: install, switch and pin multiple Node.js versions per shell and project with .nvmrc.

nvm (Node Version Manager) keeps any number of Node.js versions installed side by side and lets you switch between them per shell or per project. Instead of overwriting one globally installed Node version, you can keep Node 18 for a legacy project and Node 22 for a new one ready at the same time. With a .nvmrc file you pin the right version straight into the project, so everyone on the team automatically uses the same Node. One thing to keep in mind: nvm is not a binary but a shell function loaded at startup from your .bashrc or .zshrc – which is why nvm use only ever affects the current shell.

Install & List Versions

nvm install <version> — Install a specific Node.js version.

nvm install 20

nvm install --lts — Install the latest LTS (Long-Term Support) version.

nvm install --lts

nvm install node — Install the latest current version.

nvm install node

nvm ls — List all locally installed versions.

nvm ls

nvm ls-remote — List all available versions for installation.

nvm ls-remote

nvm ls-remote --lts — List only LTS versions available.

nvm ls-remote --lts

nvm uninstall <version> — Uninstall a specific Node.js version.

nvm uninstall 18

Switch Versions

nvm use <version> — Switch to a specific installed version.

nvm use 20

nvm use --lts — Switch to the latest installed LTS version.

nvm use --lts

nvm use node — Switch to the latest installed version.

nvm use node

nvm use system — Switch to the system-installed Node.js.

nvm use system

nvm current — Show the currently active Node.js version.

nvm current

Aliases & Defaults

nvm alias default <version> — Set the default version for new shells.

nvm alias default 20

nvm alias default lts/* — Set the default to the latest LTS.

nvm alias default lts/*

nvm alias <name> <version> — Create a custom alias for a version.

nvm alias project-a 18.19.0

nvm unalias <name> — Remove a custom alias.

nvm unalias project-a

.nvmrc & Auto-Switch

echo '<version>' > .nvmrc — Create a .nvmrc file to pin the Node version for a project.

echo '20' > .nvmrc

nvm use — Read .nvmrc and switch to that version (auto-detect).

nvm use

nvm install — Install the version specified in .nvmrc if not present.

nvm install

Utilities

nvm which <version> — Show the path to a Node.js version binary.

nvm which 20

nvm exec <version> <command> — Run a command with a specific Node version.

nvm exec 18 node -v

nvm run <version> <script> — Run a script with a specific Node version.

nvm run 20 app.js

nvm reinstall-packages <version> — Reinstall global npm packages from another version.

nvm reinstall-packages 18

nvm cache clear — Clear the nvm download cache.

nvm cache clear

nvm --version — Show the installed nvm version.

nvm --version

Conclusion

nvm takes the pain out of juggling Node.js versions by hand: you install them side by side, pin a .nvmrc per project and switch with a single nvm use. Keep in mind that each Node version has its own set of globally installed packages – after switching versions your global CLIs will be missing at first, and nvm reinstall-packages helps carry them over. The official installation runs through a curl … | bash script: as a rule you shouldn't run such pipe-to-shell commands blindly, but review the script first or pin it. Because nvm is a shell function rather than a binary, it only works in shells where it has been sourced from .bashrc/.zshrc – in cron jobs or CI it won't be available without explicit sourcing.

Further Reading

  • apk – Alpine Linux package manager
  • apt – convenient package front-end for Debian/Ubuntu
  • apt-get – classic package tool for Debian/Ubuntu