Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Last active January 15, 2026 18:54
Show Gist options
  • Select an option

  • Save HauptJ/e2a5b71fee6a0bdbb92d9e2105fa5da5 to your computer and use it in GitHub Desktop.

Select an option

Save HauptJ/e2a5b71fee6a0bdbb92d9e2105fa5da5 to your computer and use it in GitHub Desktop.
Bash script to install packages on Ubuntu with APT PPA repos
#!/usr/bin/env bash
set -e
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
declare -A pkg_map
pkg_map["ansible"]="ppa:ansible/ansible"
pkg_map["golang-go"]="ppa:longsleep/golang-backports"
for pkg in "${!pkg_map[@]}"; do
if dpkg -s $pkg >/dev/null 2>&1; then
echo "$pkg is already installed."
else
apt update
apt install -y software-properties-common
apt-add-repository --yes --update ${pkg_map[$key]}
apt install -y $pkg
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment