已安装nvm与Node/npm但终端提示‘command not found: nvm/npm’的问题求助
Hey there, let's work through this nvm issue together—this is a super common snag, so we'll get it sorted quickly!
First, Let's Check Shell Configuration
The most likely culprit is that your shell isn't loading the nvm initialization script on startup. Here's what to do:
Identify your current shell
Run this command to see which shell you're using:echo $SHELLCommon outputs are
/bin/bash(Bash) or/bin/zsh(Zsh).Verify nvm's initialization code exists in your shell config file
nvm should have added this code automatically during installation, but sometimes it misses. Open the config file matching your shell:- For Bash:
open ~/.bash_profileoropen ~/.bashrc - For Zsh:
open ~/.zshrc - For Fish:
open ~/.config/fish/config.fish
Look for these lines (for Bash/Zsh):
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_completionIf you don't see them, paste the code into the file and save it.
- For Bash:
Reload your shell config
Instead of closing and reopening your terminal, run this command (replace.zshrcwith your config file):source ~/.zshrc
Check for Homebrew Conflicts
Since you have Homebrew installed, there might be a conflict if you previously installed Node via Homebrew. Here's how to confirm:
- Run
which node—if the output is/usr/local/bin/node(Homebrew's default path), that means your system is prioritizing Homebrew's Node over nvm's. - To fix this, you can either:
- Uninstall Homebrew's Node temporarily:
brew uninstall node - Ensure nvm's path is at the top of your
PATHvariable (the initialization code we added earlier should handle this, but reloading the config ensures it takes effect).
- Uninstall Homebrew's Node temporarily:
Test It Out
After completing the steps above, run:
nvm --version npm --version
You should now see the version numbers instead of the "command not found" error. Also, which node should point to a path inside ~/.nvm/versions/node/.
内容的提问来源于stack exchange,提问作者Atharva




