Did you follow the instructions listed in the caveats?
[~] brew info nvm
nvm: stable 0.20.0, HEAD
https://github.com/creationix/nvm
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nvm.rb
==> Caveats
Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's
equivalent configuration file:
source $(brew --prefix nvm)/nvm.sh
Node installs will be lost upon upgrading nvm. Add the following above
the source line to move install location and prevent this:
export NVM_DIR=~/.nvm
Without the extra config it doesn't look like it will find NVM by default..
Answer from Doon on Stack OverflowDid you follow the instructions listed in the caveats?
[~] brew info nvm
nvm: stable 0.20.0, HEAD
https://github.com/creationix/nvm
Not installed
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nvm.rb
==> Caveats
Add the following to $HOME/.bashrc, $HOME/.zshrc, or your shell's
equivalent configuration file:
source $(brew --prefix nvm)/nvm.sh
Node installs will be lost upon upgrading nvm. Add the following above
the source line to move install location and prevent this:
export NVM_DIR=~/.nvm
Without the extra config it doesn't look like it will find NVM by default..
There are TWO things you need to do. Follow the caveats shown after installing nvm via brew, and THEN you need to activate/reload the .bash_profile/.zshrc changes.
- Run
brew install nvm - Follow caveats shown in console, mine were as follows, yours MAY be different!:
Add the following to
~/.bash_profile,~/.zshrcor your desired shell configuration file:export NVM_DIR="$HOME/.nvm" . "$(brew --prefix nvm)/nvm.sh"
- Run
. ~/.bash_profileto apply the changes you made to your .bash_profile file (Adjust as required for.zshrcand similar)
It's mentioned in nvm Github readme.
TLDR
Copy below code to your .zshrc file:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
if you take a closer look at nvm installation instructions, you will notice that there is an information about how to set a deeper shell integration.
it is even noted in brew
$ brew info nvm
...
==> 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 /Users/geek/.bash_profile or your desired shell
configuration file:
export NVM_DIR="$HOME/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
You can set $NVM_DIR to any location, but leaving it unchanged from
/usr/local/opt/nvm will destroy any nvm-installed Node installations
upon upgrade/reinstall.
Type `nvm help` for further information.
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
since you are interested in zsh deeper shell integration, do this (i intentionally do not include a snippet from the official documentation, so it will be up-to-date)
I managed to get this working by creating a .zshrc file and pasting the following into the file source /Users/YOUUSERNAME/.bash_profile.
Follow the instructions here. The NVM install on ZSH doesn't persist the path and export information.
https://gist.github.com/mike-casas/6d489bebf48d89f5109cd1395aabe150
I think you missed this step:
source ~/.nvm/nvm.sh
You can run this command on the bash OR you can put it in the file /.bashrc or ~/.profile or ~/.zshrc to automatically load it
https://github.com/creationix/nvm
Check your .bash_profile, .zshrc, or .profile file. You most likely had a problem during the installation.
You should have the following at the end of one of those files.
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh # This loads NVM
The . $HOME/.nvm/nvm.sh is the same as source $HOME/.nvm/nvm.sh
See: Sourcing a File
You can also check to see if you have a .nvm folder.
ls -a | grep .nvm
If you're missing that folder then the installation failed to run the git command. This could be due to being behind a proxy. Try running the following instead.
git clone http://github.com/creationix/nvm.git .nvm
Added this line to ./zshrc file. Working great. Original source: https://github.com/lukechilds/zsh-nvm
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
I was having the same problem after exiting the terminal the nvm command was not found. So to fix this you have to add
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
# This loads nvm bash_completion
this line of code on your .zshrc file
to do that type vim ~/.zshrc than add the following lines in the bottom and to save the file click ctrl than press :wq! to save file in vim you can also use nano
So your PAth's are not the same. This is what is causing your different terminals to not be in sync.
They both have this:
bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
zsh: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
But only your bash has this:
/Users/myuser/.nvm/versions/node/v12.22.1/bin:
You should add that to your ZSH PATH. Since you don't have a .zshrc file, do the following in Terminal;
echo 'PATH="~/.nvm/versions/node/v12.22.1/bin:$PATH"' >> ~/.zshrc
Just adding to this that: In my case I had node and nvm installed and it was working fine for a long time
nvm use 16 (my preferred node version) helped