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.
Why nvm Is Needed
Section titled “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
.nvmrcfile
Installation Steps
Section titled “Installation Steps”1. Run the nvm install script
Section titled “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 | bashThis downloads and runs the official install script from the nvm repository.
2. Check your shell config file
Section titled “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
Section titled “3. Restart the shell and verify”source ~/.zshrc # For Zsh
# source ~/.bashrc # For Bash
command -v nvm # If "nvm" is shown, installation succeededIf nvm is printed, the installation is complete.
Installing Node.js
Section titled “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
Section titled “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 versionChecking Installed Versions
Section titled “Checking Installed Versions”nvm ls # Show installed versions
nvm ls-remote # Show versions available for installationPinning a Version per Project (.nvmrc)
Section titled “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 .nvmrcIf you commit .nvmrc to the repository, everyone on the team can use the same version.
Summary
Section titled “Summary”- Install nvm with a
curlcommand - Use
nvm install --ltsto install the latest LTS release (v22 series in 2026) - Use
nvm use <version>to switch versions - Use
.nvmrcto pin a version per project
Common Problems and Fixes
Section titled “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>.