Last active
July 19, 2025 21:51
-
-
Save mikestankavich/4728909ba36b5142bd59d722210c6f43 to your computer and use it in GitHub Desktop.
Convenience script to install GitHub CLI on Ubuntu
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
#!/bin/bash | |
set -e | |
############################################################################################### | |
# This is a convenience script for installing the Github gh CLI. Invoke as follows: # | |
# curl -fsSL https://gist.github.com/yourusername/gist-hash/raw/install-gh-cli.sh | sudo bash # | |
# Author: Mike Stankavich https://github.com/mikestankavich [email protected] # | |
############################################################################################### | |
# Root check | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root (e.g., with 'sudo bash')." | |
exit 1 | |
fi | |
KEYRING_PATH="/etc/apt/keyrings/githubcli-archive-keyring.gpg" | |
SOURCE_LIST="/etc/apt/sources.list.d/github-cli.list" | |
ARCH=$(dpkg --print-architecture) | |
KEY_URL="https://cli.github.com/packages/githubcli-archive-keyring.gpg" | |
REPO_ENTRY="deb [arch=$ARCH signed-by=$KEYRING_PATH] https://cli.github.com/packages stable main" | |
# Download and install keyring | |
mkdir -p -m 755 /etc/apt/keyrings | |
TEMPFILE=$(mktemp) | |
curl -fsSL "$KEY_URL" > "$KEYRING_PATH" | |
chmod go+r "$KEYRING_PATH" | |
rm "$TEMPFILE" | |
# Add GitHub CLI apt source | |
mkdir -p -m 755 /etc/apt/sources.list.d | |
echo "$REPO_ENTRY" > "$SOURCE_LIST" | |
# Update package lists and install gh | |
apt update | |
apt install -y gh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment