Skip to content
X

nvm - Node.js Version Manager

nvm (Node Version Manager) is a tool for managing Node.js versions. It lets you install multiple Node.js versions on one computer and switch between them per project.

It is useful when project A needs Node.js v18 and project B needs Node.js v22.

If you install Node.js directly through the official installer or Homebrew, you can usually keep only one version on the machine.

With nvm, you can:

  • Keep multiple versions installed at the same time
  • Switch versions with a single command
  • Pin the version per project with a .nvmrc file

Run the following command in the terminal:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash

This downloads and runs the official install script from the nvm repository.

The install script automatically adds the following lines to ~/.zshrc for Zsh or ~/.bashrc for Bash:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

If the script did not add them automatically, add those three lines manually.

source ~/.zshrc          # For Zsh
# source ~/.bashrc       # For Bash

command -v nvm           # If "nvm" is shown, installation succeeded

If nvm is printed, the installation is complete.

nvm install --lts        # Install the latest LTS release (v22 series in 2026)
nvm install 20           # Install Node.js v20.x
nvm install --lts        # Switch to the latest LTS release
node -v                  # Check the installed version
npm i -g npm             # Update npm to the latest version (optional)

In 2026, the Node.js LTS (Long Term Support) line is v22. For new projects, I recommend using the LTS release.

nvm use 20               # Switch to Node.js v20
nvm use --lts            # Switch to the latest LTS release
nvm use 22               # Switch to Node.js v22
nvm current              # Show the current version
nvm ls                   # Show installed versions
nvm ls-remote            # Show versions available for installation

Create a .nvmrc file in the project root to pin the Node.js version used by that project.

echo "22" > .nvmrc       # Create a .nvmrc file that specifies Node.js v22
nvm use                  # Switch to the version from .nvmrc

If you commit .nvmrc to the repository, everyone on the team can use the same version.

  • Install nvm with a curl command
  • Use nvm install --lts to install the latest LTS release (v22 series in 2026)
  • Use nvm use <version> to switch versions
  • Use .nvmrc to pin a version per project

Q: nvm: command not found appears

A: Your shell configuration may not have been loaded. Run source ~/.zshrc for Zsh or source ~/.bashrc for Bash. If that does not help, check whether the nvm lines were added to the config file.

Q: Homebrew Node.js and nvm Node.js conflict

A: It is best to standardize on one approach. If you want to use nvm, uninstall the Homebrew Node.js version with brew uninstall node, then reinstall Node.js with nvm.

Q: The Node.js version switches back immediately

A: nvm use applies only to the current terminal session. If you always want a specific version, set a default with nvm alias default <version>.