Skip to content
LinkedInX

nvm - Node.js Version Manager

Prerequisites: Node.js is installed and you know basic terminal operations

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.

Why nvm Is Needed

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

Installation Steps

1. Run the nvm install script

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.

2. Check your shell config file

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.

3. Restart the shell and verify

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.

Installing Node.js

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.

Switching Versions

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

Checking Installed Versions

nvm ls                   # Show installed versions
nvm ls-remote            # Show versions available for installation

Pinning a Version per Project (.nvmrc)

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.

Summary

  • 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

Common Problems and Fixes

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>.

Reference

See the references for the external specifications and background sources used on this page.[1][2]

References

  1. Python Software Foundation, The Python Tutorial
  2. Node.js, Introduction to Node.js
Quiz