MacOS High Sierra下AWS CLI异常安装问题排查求助
Let’s work through this stubborn AWS CLI issue—sounds like a leftover installation stuck in a broken state, messing with your SAM tooling and build scripts. Here’s how to track it down and get things working again:
Step 1: Locate the problematic aws executable
First, let’s pinpoint exactly where the broken aws command is stored. Run these terminal commands:
which aws– This should return the full path to the executable (e.g.,/usr/local/bin/awsor~/Library/Python/3.7/bin/aws)- If
which awsreturns nothing, reset your shell’s hash table first withhash -r, then try again.
If you still get no output, check your PATH with echo $PATH and look for any suspicious entries that might contain old AWS files.
Step 2: Identify the original installation method
Since you confirmed it wasn’t installed via Homebrew, narrow down the possible sources:
- Pip/Pip3 installation: Run
pip3 list | grep awscli(usepipif you might have used Python 2). Ifawsclishows up here, this was a Python-based install. - Official AWS PKG installer: Check if the directory
/usr/local/awsexists—this is the default location for the official pkg install. - Manual binary download: Look for standalone
awsbinaries in common spots like/usr/local/bin,~/bin, or custom directories you added to yourPATH.
Step 3: Uninstall the broken installation
Use the method matching what you found in Step 2:
- Pip/Pip3: Uninstall with
pip3 uninstall awscli(orpip uninstall awsclifor Python 2). Confirm the process completes successfully. - AWS PKG: Run the official uninstall script with
sudo /usr/local/aws/bin/aws-uninstall. Enter your admin password when prompted. - Manual binary: Delete the executable file directly (e.g.,
rm /usr/local/bin/aws).
Step 4: Clean up residual files and PATH entries
To avoid leftover conflicts:
- Back up your AWS configuration first if you want to keep credentials/settings:
mv ~/.aws ~/.aws.bak - Open your shell configuration file (e.g.,
~/.bash_profilefor High Sierra’s default bash, or~/.zshrcif you use zsh) and remove any lines adding old AWS-related paths to yourPATH. Save the file and reload your shell withsource ~/.bash_profile.
Step 5: Reinstall AWS CLI properly
For macOS High Sierra, the most reliable methods are:
- Pip3 (user-level install, recommended):
This installs the CLI in your user directory, avoiding system permission issues. Ensurepip3 install awscli --upgrade --user~/Library/Python/3.7/bin(or your Python 3 version’s bin folder) is in yourPATH. - Official AWS PKG Installer: Download the latest macOS pkg from AWS, run the installer, and it will automatically configure your
PATHcorrectly.
Step 6: Verify the fix
Once reinstalled, test these commands to confirm everything works:
aws --version– Should return the current CLI version numbersam --version– Should now recognize the CLI and function normally- Run your build scripts to ensure they no longer hit AWS CLI-related errors
内容的提问来源于stack exchange,提问作者Sam Anthony

