Mac电脑adb: command not found问题求助——Android_Home配置异常
Hey there! Let's troubleshoot why your adb command isn't working after configuring ANDROID_HOME on your Mac. I'll walk you through common fixes step by step:
1. Ensure your shell is using the right configuration file
Mac's default terminal shell switched to zsh a while back, so if you're using the default setup, editing ~/.bash_profile might not apply to your active shell. Let's confirm:
- Run this command to check your current shell:
echo $SHELL - If the output is
/bin/zsh, you have two options:- Move your Android configuration into
~/.zshrcinstead of~/.bash_profile, or - Add this line to
~/.zshrcto load your bash profile automatically:source ~/.bash_profile
- Move your Android configuration into
2. Verify your ANDROID_HOME and PATH setup is complete
adb is located in the platform-tools folder of your Android SDK, so your config must include this path. Double-check your profile file (either ~/.bash_profile or ~/.zshrc) has these lines (replace the SDK path with your actual path from your screenshot):
export ANDROID_HOME=/Users/YourUsername/Library/Android/sdk export PATH=$PATH:$ANDROID_HOME/tools export PATH=$PATH:$ANDROID_HOME/platform-tools
A super common mistake is forgetting to add platform-tools to PATH—that's exactly where adb lives!
3. Apply configuration changes right away
After editing the profile file, you need to tell your shell to reload it without restarting:
- For bash:
source ~/.bash_profile - For zsh:
source ~/.zshrc
4. Confirm the configuration is working
Let's verify the paths are set correctly:
- Run
echo $ANDROID_HOME—it should output your exact SDK path. - Run
echo $PATH—look for your SDK'splatform-toolsdirectory in the output. - You can also test directly by navigating to your SDK's
platform-toolsfolder and running:./adb version
If this works, the issue is definitely with your PATH configuration.
5. Double-check you saved the profile file correctly
When using vi to edit the file, make sure you saved properly:
- Press
ESCto exit edit mode - Type
:wqand press Enter to save and quit
You can confirm the content is there by running:
cat ~/.bash_profile
6. Restart your Terminal
Sometimes changes don't take full effect until you close and re-open your Terminal window. Give that a try if the above steps don't resolve the issue.
内容的提问来源于stack exchange,提问作者Anjali

