Use multiple Node.js versions on one computer

Switch Node.js versions with nvm, record a project version, and keep local shells, editors, and CI using the intended runtime.

Best practices
Illustration accompanying a Node.js development guide

A version manager lets several Node.js releases coexist without repeatedly replacing a system installation. On macOS, Linux, or a Unix-like shell, nvm is a common choice. Windows users can use the separate nvm-windows project; its installation and switching mechanism differ from nvm.

Install and select a version

After installing nvm using its documented instructions and initializing your shell:

nvm install 22
nvm install 24
nvm use 24
node --version
npm --version
nvm alias default 24

nvm use changes the current shell. The default alias selects version 24 in newly initialized shells; it does not change processes already running. These numbers are major-version selectors, so installation resolves an available release within that major.

Useful inspection commands include nvm ls, nvm ls-remote, and nvm current. nvm install --lts selects an LTS release, but a moving selector is less reproducible than a specific patch version.

Record the project's runtime

printf '24\n' > .nvmrc
nvm install
nvm use

With no version argument, these commands read .nvmrc. Use a complete version number when the team needs an exact release. Plain nvm does not automatically switch every time you enter a directory; that behavior requires shell integration. CI also needs explicit configuration to read the file or select the equivalent version.

The engines field documents compatibility rather than selecting a runtime:

{
  "engines": { "node": ">=22 <25" }
}

npm normally treats this as advisory unless stricter settings apply. Check the actual interpreter used by your IDE, test runner, and deployment environment as well as the interactive terminal.

Windows and other options

After installing nvm-windows, its nvm install VERSION, nvm use VERSION, and nvm list commands manage Windows installations through a symlink. Follow that project's instructions for permissions and existing installations; Unix nvm shell commands and aliases are not interchangeable with it.

Other choices include n, fnm, and Volta. fnm supports directory-based switching when its shell integration is configured. Volta can pin a project toolchain and select it through its shims. Choose one approach consistently to avoid competing PATH entries. Containers can package a runtime and filesystem dependencies, but the host, architecture, and runtime configuration still matter.

Global packages and common problems

nvm keeps global packages associated with each installed Node version. To copy packages while installing another version, use nvm install 24 --reinstall-packages-from=22; review compatibility afterward. Prefer project dependencies for build tools so a developer's global installation does not silently determine the build.

If a switch appears ineffective, inspect node --version, nvm current, and the resolved executable path. Restart an editor or terminal that captured an older environment. An already running application continues using the interpreter with which it started.

See the nvm guide and nvm-windows documentation.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting