Last active
January 15, 2026 18:54
-
-
Save HauptJ/e2a5b71fee6a0bdbb92d9e2105fa5da5 to your computer and use it in GitHub Desktop.
Bash script to install packages on Ubuntu with APT PPA repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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