Skip to content

Instantly share code, notes, and snippets.

@AMMullan
Last active January 16, 2025 11:58
Show Gist options
  • Save AMMullan/082c9eea10673918ae2d6dd2e2d262de to your computer and use it in GitHub Desktop.
Save AMMullan/082c9eea10673918ae2d6dd2e2d262de to your computer and use it in GitHub Desktop.
Script to install/upgrade AWS CLI in $HOME
#!/bin/bash
#
# This script can be used to install the AWS CLI in $HOME/.local/ rather than global
# Why? Because then we don't have to keep using sudo needlessly.
#
# It creates a choices.xml which the pkg installer uses to select the correct path.
# The binaries are then linked to the $HOME/.local/bin folder - make sure this is in your $PATH
#
cd $HOME
INSTALL_PATH="$HOME/.local"
if command -v aws 2>&1 >/dev/null ; then
echo "Current Version: $(aws --version)"
echo
fi
echo """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>choiceAttribute</key>
<string>customLocation</string>
<key>attributeSetting</key>
<string>${INSTALL_PATH}</string>
<key>choiceIdentifier</key>
<string>default</string>
</dict>
</array>
</plist>""" > choices.xml
echo "Downloading AWS CLI Package..."
curl -s "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
echo "Installing..."
installer -pkg AWSCLIV2.pkg -target CurrentUserHomeDirectory -applyChoiceChangesXML choices.xml
ln -sf ~/.local/aws-cli/aws ~/.local/bin/
ln -sf ~/.local/aws-cli/aws_completer ~/.local/bin/
echo
echo "New Version: $(aws --version)"
rm -f choices.xml AWSCLIV2.pkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment