I’m trying to install nvm Mac on my system, but even after running the installation via Homebrew, the terminal doesn’t recognize the nvm command.
I have Node.js working fine:
$ node -v
v21.3.0
But when I run:
$ nvm -v
zsh: command not found: nvm
And when I try to install again:
$ brew install nvm
Warning: nvm 0.39.5 is already installed and up-to-date.
It seems like install nvm Mac went through, but nvm isn’t loading in my shell. Is there something I need to add to my .zshrc or another step I’m missing to finish the setup? Would appreciate any help!
So, I’ve run into this situation with Homebrew installs where nvm isn’t properly hooked into the shell profile. One common thing is that Homebrew doesn’t automatically add the necessary lines to your .zshrc
file. To fix this, you need to manually add these lines:
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"
Then, run this command:
source ~/.zshrc
This will make sure that nvm gets properly recognized in your terminal session. Without adding those lines, it’s like the command exists but doesn’t register, which is why you keep seeing “command not found.” It should work after this!
Another thing you could try, especially if you want to skip the extra Homebrew setup, is installing nvm directly using the official script. Sometimes Homebrew complicates things more than it should. Just run this:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
This will automatically add the necessary exports and sourcing steps to either your .zshrc
or .bash_profile
. Once that’s done, restart your terminal (or run source ~/.zshrc
), and nvm should work perfectly fine. This is the method the nvm maintainers recommend, so it’s pretty solid.
Here’s something that’s easy to miss: you should double-check that your .zshrc
is actually being loaded. To do that, run:
echo $ZSH_VERSION
If it doesn’t return anything, it might mean your shell isn’t Zsh, or maybe you’re editing the wrong profile. On older macOS or custom terminals, it could still be referencing .bash_profile
. You can force it to load by adding this to the top of your .zshrc
:
[ -f ~/.nvm/nvm.sh ] && source ~/.nvm/nvm.sh
Alternatively, you can manually load it by running:
source /opt/homebrew/opt/nvm/nvm.sh
This should immediately register nvm and help you figure out if your configuration is just being ignored.