Skip to content

Instantly share code, notes, and snippets.

@bewithdhanu
Last active July 2, 2024 08:28
Show Gist options
  • Save bewithdhanu/9414040de4d3f6f310efde7083890441 to your computer and use it in GitHub Desktop.
Save bewithdhanu/9414040de4d3f6f310efde7083890441 to your computer and use it in GitHub Desktop.
AWS CLI Setup Script
#!/bin/bash

# Update package list and install python3-pip
sudo apt update
sudo apt install -y python3-pip

# Install AWS CLI
pip3 install awscli --upgrade-strategy only-if-needed --break-system-packages

# Add the PATH update to .bashrc
echo "export PATH=/usr/local/bin:\$PATH" >> ~/.bashrc

# Source the updated .bashrc
source ~/.bashrc

# Print AWS CLI version
aws --version

echo "AWS CLI setup complete. Please restart your terminal or run 'source ~/.bashrc' to apply the PATH changes."

This script does the following:

  1. Updates the package list and installs python3-pip
  2. Installs the AWS CLI using pip3 with the specified options
  3. Adds the PATH export line to the end of .bashrc
  4. Sources the updated .bashrc to apply the changes in the current session
  5. Prints the AWS CLI version
  6. Outputs a message to remind the user to restart their terminal or source .bashrc again

To use this script:

  1. Save it to a file, for example, aws_cli_setup.sh
  2. Make it executable with chmod +x aws_cli_setup.sh
  3. Run it with ./aws_cli_setup.sh

Note that this script will append the PATH export to .bashrc every time it's run. If you plan to run it multiple times, you might want to add a check to see if the line already exists in .bashrc before adding it.

#!/bin/bash
# Update package list and install python3-pip
sudo apt update
sudo apt install -y python3-pip
# Install AWS CLI
pip3 install awscli --upgrade-strategy only-if-needed --break-system-packages
# Add the PATH update to .bashrc
echo "export PATH=/usr/local/bin:\$PATH" >> ~/.bashrc
# Source the updated .bashrc
source ~/.bashrc
# Print AWS CLI version
aws --version
echo "AWS CLI setup complete. Please restart your terminal or run 'source ~/.bashrc' to apply the PATH changes."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment