Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install nvm on Mac?

Tags:

node.js

nvm

I am unable to install nvm on my Mac. I have installed Node.js and it's running perfectly fine but unable to install nvm on my system.

While checking Node version it's showing:

$ node -v
v21.3.0

but when I try to check nvm version it gives me an error:

$ nvm -v
zsh: command not found: nvm

When I try to install nvm it gives me an error :

$ brew install nvm

Warning: nvm 0.39.5 is already installed and up-to-date.
To reinstall 0.39.5, run:
brew reinstall nvm
like image 523
Ritesh Avatar asked Aug 30 '25 13:08

Ritesh


2 Answers

To resolve this issue, ensure that nvm is properly set up in your shell configuration. Since you are using zsh, add the following lines to your .zshrc file:

brew upgrade
brew install nvm
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "$(brew --prefix nvm)/nvm.sh" ] && \. "$(brew --prefix nvm)/nvm.sh"' >> ~/.zshrc
echo '[ -s "$(brew --prefix nvm)/etc/bash_completion.d/nvm" ] && \. "$(brew --prefix nvm)/etc/bash_completion.d/nvm"' >> ~/.zshrc
source ~/.zshrc

After running these commands, nvm should be set up correctly. You can verify the installation by checking the nvm version:

$ nvm --version
like image 131
hemant jangra Avatar answered Sep 02 '25 12:09

hemant jangra


Looking at the warning which you added in your question, I surmise that nvm is installed on your machine but may not have been setup properly. Nevertheless, adding full steps for you to verify which one you missed and fix the same.

1. Confirm nvm is installed

Before making changes, check if nvm exists:

# confirm nvm is installed
$ brew list | grep nvm
# if the above doesn't return anything, install nvm
$ brew install nvm

2. Ensure your system is in good shape

Sometimes Homebrew issues prevent nvm from working properly. For that run:

$ brew doctor
# If you see any warnings, follow the suggested fixes and 
# rerun brew doctor until everything looks good. 

3. Create the nvm directory (if missing)

$ mkdir -p ~/.nvm

4. Add nvm to your shell configuration

Manually add these lines to ~/.zshrc:

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"

Save the file and reload the configuration:

$ source ~/.zshrc

5. Verify and Restart

Check if nvm is now working:

$ nvm -v

If you still get an error, restart your terminal and try again. Sometimes failing to do this might also lead to issues.

like image 40
mandy8055 Avatar answered Sep 02 '25 10:09

mandy8055