Fixing 'nvm: command not found' on macOS: A Quick Guide

beginner๐ŸŽ macOS2026-07-06| macOS (Sonoma, Ventura, Monterey), Zsh or Bash, Node Version Manager (nvm) v0.39.0+

Error Message

nvm: command not found
#nvm#node#zsh#macos#terminal#homebrew

The ProblemYou just finished running the curl or wget install script for Node Version Manager. Everything looked fine. But the moment you open a new terminal window or restart your Mac, you're greeted with a frustrating message:

zsh: command not found: nvm

If you're on an older Mac (pre-2019), you might see bash: nvm: command not found instead. This happens because your shell doesn't know where nvm lives yet.

The 60-Second FixMost Macs now use Zsh as the default shell. If the installer didn't automatically update your configuration, you can do it manually in four quick steps:

  • Open your terminal and type: nano ~/.zshrc- Scroll to the bottom and paste these three lines:export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # Loads nvm bash_completion- Press Ctrl + O, then Enter to save. Press Ctrl + X to exit the editor.- Apply the changes immediately: source ~/.zshrc## What Went Wrong?Behind the scenes, nvm isn't a standalone program like Chrome or Slack. It is a shell function. To work, it must be "sourced" (loaded) every time your terminal starts. The installer usually tries to add the loading code to your profile, but it often fails for a few reasons:
  • Missing Config Files: Fresh macOS installs often don't have a .zshrc file. If the file isn't there, the installer simply gives up.- The Zsh Switch: Since macOS Catalina (10.15), Apple switched from Bash to Zsh. Many older tutorials still point users to .bash_profile, which Zsh ignores.- Write Permissions: Security settings on newer macOS versions (like Sonoma 14.0) can sometimes block scripts from modifying your home directory.## Detailed Solutions for Every Setup### Method 1: For Modern macOS (Zsh)Run echo $SHELL. If the output is /bin/zsh, follow these steps to ensure your configuration is permanent.
  • Verify if the file exists: ls -a ~ | grep .zshrc.- If you see no output, create it: touch ~/.zshrc.- Open the file: open -e ~/.zshrc. This opens TextEdit, which might be easier than nano for some.- Paste the NVM initialization code at the very end of the document.- Save and restart your terminal.### Method 2: For Legacy macOS (Bash)If your shell is /bin/bash, the process is identical, but the filename changes. You will need to edit ~/.bash_profile or ~/.profile instead. Use source ~/.bash_profile to refresh your settings after saving.

Method 3: The Homebrew ExceptionDid you use brew install nvm? While the NVM creators officially discourage using Homebrew, it remains a popular choice for Mac users. If you went this route, the standard paths won't work. Add this specific block to your .zshrc instead:

export NVM_DIR="$HOME/.nvm"
mkdir -p $NVM_DIR
[ -s "$(brew --prefix)/opt/nvm/nvm.sh" ] && \. "$(brew --prefix)/opt/nvm/nvm.sh"
[ -s "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm" ] && \. "$(brew --prefix)/opt/nvm/etc/bash_completion.d/nvm"

Verifying the FixDon't just assume it's working. Test it. Run this command:

command -v nvm

If the setup is correct, the terminal will simply return the word nvm. If it returns nothing, double-check your file paths. You can also try nvm --version; as of late 2023, you should likely see something like 0.39.5 or higher.

Common Pitfalls on Apple SiliconNewer Macs (M1, M2, and M3 chips) handle paths differently than older Intel Macs. Homebrew, for instance, installs to /opt/homebrew instead of /usr/local. By using the $(brew --prefix) command in your config file, you ensure the path is always correct, regardless of which chip your Mac uses.

Related Error Notes