The "zsh: command not found: nvm" error occurs because the Zsh shell does not know where the Node Version Manager (NVM) binary is located or how to initialize it. To fix this, you must add the NVM initialization script to your .zshrc configuration file, which tells the shell to load NVM every time a new terminal window opens.

What You'll Need

  • A Mac running macOS (Catalina or newer, as Zsh is the default shell).
  • The Terminal app (found in Applications > Utilities).
  • NVM already installed via the official install script (if not yet installed, you must run the curl or wget command from the official NVM GitHub repository first).
  • Basic familiarity with copying and pasting commands into a command-line interface.

Step-by-Step

  1. Verify if NVM is actually installed: Before editing configuration files, check if the NVM folder exists in your home directory. Open Terminal and type ls -a ~. Look for a directory named .nvm. If you do not see this folder, NVM is not installed on your system, and adding the configuration lines will not work. You must install it first using the official installation script provided by the NVM maintainers.
  2. Open your Zsh configuration file: Zsh uses a hidden file called .zshrc located in your user home directory to load settings and paths. To open this file for editing, type nano ~/.zshrc in your terminal. Nano is a simple text editor built into the macOS terminal. If the file is empty, that is normal; it just means you haven't customized your shell yet.
  3. Add the NVM initialization code: Scroll to the bottom of the file and paste the following block of code exactly as written. This code defines the NVM directory and loads the necessary shell functions:

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

    Ensure there are no accidental spaces at the start of these lines.
  4. Save and exit the editor: Once the code is pasted, press Control + O (the letter O) to write the changes to the disk. When prompted for the filename, simply press Enter to confirm. After saving, press Control + X to exit the Nano editor and return to the command prompt.
  5. Refresh your shell environment: The changes you made to .zshrc do not take effect in the current session automatically. You must tell the shell to read the file again. Type source ~/.zshrc and press Enter. Alternatively, you can completely close the Terminal app and reopen it.
  6. Test the command: Now, verify that the shell recognizes the command by typing nvm --version. If the installation was successful and the path is correctly configured, the terminal will return a version number (e.g., 0.39.x) instead of the "command not found" error.
  7. Install a Node version: To ensure NVM is fully functional, try installing the latest stable version of Node.js by typing nvm install --lts. Once finished, type node -v to confirm that Node is active and accessible.

Common Mistakes

One of the most frequent errors is installing NVM via Homebrew. While Homebrew is a powerful package manager for macOS, the NVM maintainers explicitly discourage using it because it can lead to pathing conflicts and unexpected behavior during version switching. If you installed NVM via brew install nvm, the initialization lines required in .zshrc are different from the official script, often leading to the "command not found" error even after following standard guides. It is highly recommended to uninstall the Homebrew version and use the official curl script.

Another common mistake is editing the wrong configuration file. Users coming from older versions of macOS or Linux may try to edit .bash_profile or .bashrc. Since macOS Catalina, the default shell is Zsh, which ignores those files entirely. If you place your NVM paths in .bash_profile, Zsh will never see them, and the command will remain "not found." Always ensure you are editing .zshrc.

Typing errors in the source command are also common. Users sometimes type source .zshrc (without the tilde) while they are not in their home directory. The tilde (~) is a shortcut for the home directory path. Without it, the terminal looks for the file in the current folder, fails to find it, and the shell environment remains un-updated.

Tips

To make your workflow faster, consider creating an alias for your most-used Node versions. If you frequently switch between a legacy project using Node 14 and a modern project using Node 20, you can add aliases to your .zshrc file. While NVM has its own alias command (nvm alias default [version]), you can also create shell shortcuts to switch environments instantly.

If you use multiple terminal emulators (such as iTerm2 and the default Apple Terminal), remember that they both use the same .zshrc file. Any change you make once will apply across all your terminal applications. This ensures a consistent development environment regardless of which app you use to access the command line.

Keep your NVM updated. Occasionally, the NVM tool itself receives updates that improve performance or add support for newer versions of Node.js. You can update NVM by running the official installation script again; it will detect the existing installation and update the binaries without deleting your installed Node versions.

Troubleshooting

If you have followed the steps and still see "command not found," first check for the existence of the .zshrc file. Some macOS installations do not create this file by default. If you tried to source it and got an error saying the file does not exist, you must create it using touch ~/.zshrc before adding the NVM code.

Check for permission issues. If you receive a "Permission denied" error when trying to save the file or run the source command, avoid using sudo to edit your .zshrc. The configuration file should be owned by your user account, not the root user. If permissions are messed up, run sudo chown [yourusername] ~/.zshrc to reclaim ownership of the file.

Verify the NVM directory path. If you installed NVM in a custom location instead of the default $HOME/.nvm, the initialization script provided in the steps above will fail. Open your terminal and type find ~ -name "nvm.sh" to locate where the script actually resides. Once you find the path, replace $HOME/.nvm in your .zshrc file with the actual absolute path to that folder.

If you are using a corporate Mac with security software like Jamf or SentinelOne, some scripts may be blocked from executing in the home directory. If the source command fails silently or gives a security warning, check with your IT administrator to see if shell script execution is restricted in the ~/.nvm directory.

Frequently Asked Questions

Why does this happen every time I restart my Mac?

This happens if you ran the NVM initialization commands directly in the terminal window instead of adding them to the .zshrc file. Commands typed directly into the terminal are only active for that specific session. Adding them to .zshrc ensures they run automatically every time the shell starts.

Can I use NVM with both Bash and Zsh?

Yes, but you must add the initialization code to both .bash_profile (for Bash) and .zshrc (for Zsh). Since macOS uses Zsh by default, the .zshrc file is the priority for most users.

Does NVM interfere with other versions of Node installed via the official installer?

Yes, it can. If you previously installed Node.js using the .pkg installer from the official Node website, that version is installed globally in /usr/local/bin. This can cause conflicts. It is best to uninstall the global version of Node before using NVM to manage your versions.

What is the difference between nvm install and nvm use?

nvm install [version] downloads and installs a specific version of Node.js onto your hard drive. nvm use [version] switches the active version in your current terminal session to one that is already installed.

Will this fix the error for my IDE's integrated terminal?

Yes. IDEs like VS Code or WebStorm typically launch a Zsh shell. Once the .zshrc file is correctly configured and saved, the integrated terminal will load those settings and recognize the nvm command automatically.