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 20nvm install --lts — Install the latest LTS (Long-Term Support) version.
nvm install --ltsnvm install node — Install the latest current version.
nvm install nodenvm ls — List all locally installed versions.
nvm lsnvm ls-remote — List all available versions for installation.
nvm ls-remotenvm ls-remote --lts — List only LTS versions available.
nvm ls-remote --ltsnvm uninstall <version> — Uninstall a specific Node.js version.
nvm uninstall 18Switch Versions
nvm use <version> — Switch to a specific installed version.
nvm use 20nvm use --lts — Switch to the latest installed LTS version.
nvm use --ltsnvm use node — Switch to the latest installed version.
nvm use nodenvm use system — Switch to the system-installed Node.js.
nvm use systemnvm current — Show the currently active Node.js version.
nvm currentAliases & Defaults
nvm alias default <version> — Set the default version for new shells.
nvm alias default 20nvm 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.0nvm 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' > .nvmrcnvm use — Read .nvmrc and switch to that version (auto-detect).
nvm usenvm install — Install the version specified in .nvmrc if not present.
nvm installUtilities
nvm which <version> — Show the path to a Node.js version binary.
nvm which 20nvm exec <version> <command> — Run a command with a specific Node version.
nvm exec 18 node -vnvm run <version> <script> — Run a script with a specific Node version.
nvm run 20 app.jsnvm reinstall-packages <version> — Reinstall global npm packages from another version.
nvm reinstall-packages 18nvm cache clear — Clear the nvm download cache.
nvm cache clearnvm --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
- nvm – GitHub project – source code, installation and full documentation
- Node.js – Releases & versions – LTS schedule and supported Node versions