When I installed VSCode, oh-my-zsh and NVM using homebrew I had the same issue. It appears to put wrong paths in ~/.zshrc (might be the same for bash).
Solution:
- Open ~/.zshrc or ~/.bashrc
- Create a backup of that file in case something goes wrong
- Compare paths under the line
export NVM_DIR="$HOME/.nvm"
- Now you need to fix the two paths if different than those below
[ -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
- Type
source ~/.zshrcorsource ~/.bashrcin terminal depending on what you use. - Restart VSCode built-in terminal and see if that helped. Good luck!
When I installed VSCode, oh-my-zsh and NVM using homebrew I had the same issue. It appears to put wrong paths in ~/.zshrc (might be the same for bash).
Solution:
- Open ~/.zshrc or ~/.bashrc
- Create a backup of that file in case something goes wrong
- Compare paths under the line
export NVM_DIR="$HOME/.nvm"
- Now you need to fix the two paths if different than those below
[ -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
- Type
source ~/.zshrcorsource ~/.bashrcin terminal depending on what you use. - Restart VSCode built-in terminal and see if that helped. Good luck!
I also had the same issue after installing nvm and tried to run nvm command in VS Code terminal. This is how I solve it:
Prerequisites:
- macOS Sonoma v14.0
- already install Homebrew (mine is v4.1.14)
Steps:
- Right after installing nvm with brew, create a .nvm folder
mkdir .nvm - Create a .zshrc file in Home directory, same as .nvm
- Open and add this code below to the .zshrc file
source $(brew --prefix nvm)/nvm.sh
- Back to terminal, execute the .zshrc by running
source ~/.zshrc - Restart the VS Code and try to run a nvm command
May this help you!
Videos
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
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
On Mac OS , I switched to the zsh and got this fixed. These following steps fixed the issue :
- On your VsCode in Mac :
shift + command + P. - On the Prompt > type :
Terminal: Select Default Profile, then "Click it". Note, as you type you will find this option in the auto-complete . - Click the option for zsh or your desired shell.
- Restart VSCode .
now npm will work in your vscode terminal.
By default, Visual Studio Code runs shell commands like npm in a loginless shell. If you installed NVM, Visual Studio Code may have no indication where to find npm to run it.
Put the following lines are in .bash_profile: (Note: Not .bashrc.)
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
Add this setting to settings.json:
"terminal.integrated.shellArgs.linux": ["-l"]
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