I was facing the same issue after installing nvm. Whenever my iTerm / terminal restarts, nvm is gone.
Steps I followed to make it work.
After installing it, update the Homebrew package list and install NVM.
brew update
brew install nvm
Next, create a directory for NVM.
mkdir ~/.nvm
Now add these lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later)
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Echoing $NVM_DIR should now return your NVM directory
:$ echo $NVM_DIR
/Users/username/.nvm
Now running nvm -v
should return nvm’s options.
To see what Node versions are available to install run:
nvm ls-remote
For me, I just needed the latest point release of Node version 11 so I ran
nvm install 11
After installing you can verify what is installed with
nvm ls
If you have multiple versions and you want to specify which version you would like to use, simply use:
nvm use 11
to use Node version 11.
Switching back to, let’s say, version 12 would be as easy as nvm use 12.
After switching to node version 11, all my packages installed properly.