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:
brew list | grep nvm
If this returns nvm
, proceed to configuration. If not, install it:
brew install nvm
Create Required Directory
nvm needs a directory to store Node.js versions:
mkdir -p ~/.nvm
Configure Your Shell
Edit Your Shell Profile
Open your.zshrc
file (or.bash_profile
for older macOS versions) with:bashnano ~/.zshrc
Add Configuration Lines
Paste these at the bottom of the file:bashexport 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"
Save and Apply Changes
PressCTRL+O
→Enter
→CTRL+X
to save. Then reload:bashsource ~/.zshrc
Verify nvm Functionality
Check successful setup:
nvm --version
# Should output version (e.g., 0.39.5)
::: troubleshooting If nvm is still not recognized:
- Restart your terminal completely
- Manually source nvm:bash
source ~/.nvm/nvm.sh
- Check Homebrew integrity:bashFix any reported issues :::
brew doctor
Test Node Installation via nvm
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:
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.