brew update
brew install nvm
mkdir ~/.nvm
vim ~/.bash_profile
// and, add the below lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or newer versions)
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
//now run this
source ~/.bash_profile
nvm -v