Fix error: zsh: command not found: nvm in MacOS using Brew

If you encounter the error: zsh: command not found: nvm after installing nvm with brew install nvm, follow these steps to fix it.

Temp Fix

Run the command source ~/.nvm/nvm.sh

Permanent Fix

Follow these steps:

Step 1: Get the missing steps

Run brew info nvm

Read the caveat section, which includes:

brew info nvm
==> nvm: stable 0.40.2 (bottled), HEAD
Manage multiple Node.js versions
==> Caveats
Please note that upstream has asked us to make explicit managing
nvm via Homebrew is unsupported by them and you should check any
problems against the standard nvm install method prior to reporting.

You should create NVM's working directory if it doesn't exist:
  mkdir ~/.nvm

Add the following to your shell profile e.g. ~/.profile or ~/.zshrc:
  export NVM_DIR="$HOME/.nvm"
  [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
  [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Step 2: Create .nvm Directory

Navigate to your home directory and check for .nvm:

cd ~/
ls -a

If .nvm is not found, create it: mkdir ~/.nvm

Step 3: Edit ~/.zshrc

Edit the .zshrc file:

nano ~/.zshrc

Add the following lines at the bottom(copied from output of brew info):

export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"  # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"  # This loads nvm bash_completion

Save the file with control + O and exit with control + X.

Restart the terminal, and the nvm command should work.