Skip to content

NVM Installation and Setup on macOS

Problem

You've attempted to install Node Version Manager (nvm) on macOS using Homebrew, and while Homebrew reports that nvm is already installed, running nvm --version returns zsh: command not found: nvm. The core issue is missing shell configuration that enables the terminal to recognize the nvm command.

This occurs because Homebrew installations require manual setup instructions added to your shell configuration file (.zshrc or .bash_profile) before the commands become available.

Solution: Configure nvm in Your Shell

Verify Installation Status

First, confirm nvm is actually installed through Homebrew:

bash
brew list | grep nvm

If this returns nvm, proceed to configuration. If not, install it:

bash
brew install nvm

Create Required Directory

nvm needs a directory to store Node.js versions:

bash
mkdir -p ~/.nvm

Configure Your Shell

  1. Edit Your Shell Profile
    Open your .zshrc file (or .bash_profile for older macOS versions) with:

    bash
    nano ~/.zshrc
  2. Add Configuration Lines
    Paste these at the bottom of the file:

    bash
    export NVM_DIR="$HOME/.nvm"
    [ -s "$(brew --prefix nvm)/nvm.sh" ] && . "$(brew --prefix nvm)/nvm.sh"
    [ -s "$(brew --prefix nvm)/etc/bash_completion.d/nvm" ] && . "$(brew --prefix nvm)/etc/bash_completion.d/nvm"
  3. Save and Apply Changes
    Press CTRL+OEnterCTRL+X to save. Then reload:

    bash
    source ~/.zshrc

Verify nvm Functionality

Check successful setup:

bash
nvm --version
# Should output version (e.g., 0.39.5)

::: troubleshooting If nvm is still not recognized:

  1. Restart your terminal completely
  2. Manually source nvm:
    bash
    source ~/.nvm/nvm.sh
  3. Check Homebrew integrity:
    bash
    brew doctor
    Fix any reported issues :::

Test Node Installation via nvm

bash
nvm install node  # Installs latest Node.js version
nvm use node      # Sets the version as active
node -v           # Verify version

NOT RECOMMENDED

Avoid manually removing Node-related files from /usr/local/bin or /opt/homebrew/Cellar. Always use Homebrew for uninstallation:

bash
brew uninstall node@version

Manually deleting files can cause dependencies issues and corrupted installations.

Conclusion

The nvm command must be enabled in your shell configuration file after Homebrew installation. By updating .zshrc with the correct paths and environment variables, you enable nvm to manage Node.js versions effectively. This solution maintains your existing Node installations while adding proper version management control.