Skip to content

Guide · Open source

How to use nvm: install Node.js versions and switch between them

Updated · written with AI from the project's own documentation and checked against our catalogue data

nvm (Node Version Manager) is a small POSIX-compliant bash script that lets you install several Node.js versions on one computer and switch between them from the terminal. This guide shows you how to install nvm, install and switch Node.js versions, and pin a version for a project with a .nvmrc file.

nvmnvm-sh/nvm · ★ 95.7k · MIT

Quick start

  1. 1Check the prerequisites. You need a POSIX-compatible shell such as bash or zsh, plus curl, wget, or git for the installer.
  2. 2Run the install script. Run the cURL or Wget command from the README to clone nvm to ~/.nvm and update your profile file.
  3. 3Open a new terminal. Start a new shell session so the profile snippet loads nvm.
  4. 4Install a Node.js version. Run nvm install with the major version you need, such as 24.
  5. 5Switch versions. Run nvm use with another installed version and confirm with node -v.
  6. 6Pin the version for a project. Add a .nvmrc file to the project directory so the team uses the same Node.js version.

Install nvm with the install script

To install or update nvm, run the install script. You can use either cURL or Wget. The script clones the nvm repository to ~/.nvm and tries to add the source lines to your profile file (~/.bashrc, ~/.bash_profile, ~/.zshrc, or ~/.profile).

The installer can use git, curl, or wget to download nvm, whichever is available. If the script edits the wrong profile file, set the PROFILE environment variable to the profile file's path and rerun the installer.

  • Set XDG_CONFIG_HOME if you want nvm files placed there instead of ~/.nvm.
  • Add --no-use to the end of the loading snippet to postpone using nvm until you run nvm use yourself.
  • Set PROFILE=/dev/null before running the script if you do not want it to edit your shell config.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh | bash

Load nvm in your shell

nvm is installed per user and loaded in each shell session. The installer adds this snippet to your profile file so nvm loads when you open a terminal. If it is missing, add the snippet yourself and then open a new terminal.

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Install and switch Node.js versions

Use nvm install to download a Node.js version and nvm use to switch to it. The README example installs version 24, then switches to 22 and 20, checking the active version with node -v each time.

Because nvm is invoked per shell, a version you switch to with nvm use applies to that terminal session.

  • nvm install 24 installs a Node.js release.
  • nvm use 22 switches the current shell to that version.
  • node -v shows the active Node.js version.
$ nvm install 24 Now using node v24.14.0 (npm v11.9.0) $ node -v v24.14.0 $ nvm use 22 Now using node v22.22.1 (npm v10.9.4) $ node -v v22.22.1 $ nvm use 20 Now using node v20.20.1 (npm v10.8.2) $ node -v v20.20.1

Pin a Node.js version per project with .nvmrc

A .nvmrc file in a project directory records the Node.js version that project needs. Teams use it so everyone runs the same version. You can also run nvm use automatically when you enter a directory that has a .nvmrc file; the README describes this under Deeper Shell Integration for bash, zsh, and fish.

The Docker example in the README creates a .nvmrc file and runs nvm install to read it.

  • Commit .nvmrc to your project so teammates share the version.
  • Use the Deeper Shell Integration section of the README for automatic switching setup.

Know the platform limits

nvm works on any POSIX-compliant shell, including sh, dash, ksh, zsh, and bash. The README names unix, macOS, and Windows WSL as the supported platforms. Native PowerShell or cmd on Windows is not covered by the README, so use WSL on Windows.

If you run nvm in Docker, the README notes that non-interactive bash does not source profile files, so you need to set BASH_ENV or source nvm.sh in your build.

  • Supported: unix, macOS, Windows WSL.
  • Not covered by the README: native Windows PowerShell or cmd.

What people use it for

  • Running a project that needs Node.js 20 while another project needs Node.js 24.
  • Pinning a shared Node.js version for a team with a .nvmrc file.
  • Trying a specific Node.js release before upgrading a system-wide install.
  • Building a Docker image that needs a particular Node.js version, as shown in the README's Docker examples.

Frequently asked questions

How do I install nvm?

Run the install script from the README with cURL or Wget. It clones nvm to ~/.nvm and tries to add the loading snippet to your profile file. Open a new terminal afterwards.

Does nvm work on Windows?

The README describes support for unix, macOS, and Windows WSL. It does not describe native PowerShell or cmd, so use WSL on Windows.

What do I need to run nvm?

A POSIX-compatible shell such as bash or zsh, and curl, wget, or git for the installer. nvm is a shell script, so it runs in those shells.

Is nvm free to use?

nvm is released under the MIT licence, as stated in the project's licence information.

What is a .nvmrc file?

It is a file in a project directory that records the Node.js version the project needs. Teams commit it so everyone uses the same version.

What are alternatives to nvm?

Comparable projects include fnm, volta, n, and asdf. Choose based on your shell, platform, and how you want versions managed.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

nvm suits developers and teams who work on several Node.js projects, or who pin versions with .nvmrc, on macOS, Linux, or Windows WSL. If you only ever use one Node.js version, or you use native Windows PowerShell or cmd, a system install, a direct download, or one of the comparable projects may be simpler.

Install options & downloads