Mastering GitHub CLI Installation on Linux: Streamline Your Dev Workflow
Web UIs slow down incident response. Context switches disrupt focus in CI/CD pipelines. When a repository merge or deployment coordination is at stake, the ability to interact with GitHub directly from the terminal pays off immediately. That’s the role of the GitHub CLI (gh
).
Below, you'll find a distribution-specific breakdown of installation steps—vetted on Ubuntu 22.04 LTS, Fedora 39, CentOS 8 Stream, and Arch Linux (2024.06 snapshot). These steps are based on field deployments, with a few practical observations and workarounds added.
Is the GitHub CLI Necessary?
- Terminal-based GitOps: Direct issue tracking, PR management, and repository status—automated and scriptable.
- Reduced browser dependency: Faster incident triage; less cognitive overhead.
- Batch operations: Manipulate multiple issues or merges via shell scripting; integrate with Ansible or other automation stacks.
Notably, gh
can be combined with jq or yq for custom pipeline filtering. Integration with credential managers (e.g., gnome-keyring
, libsecret
) is seamless post-authentication.
Distribution-Specific Installation
Distribution | Package Manager | Notes |
---|---|---|
Ubuntu/Debian | apt | Keyring required |
Fedora | dnf | RPM repo add mandatory |
CentOS/RHEL | yum | EPEL repo prerequisite |
Arch Linux | pacman | Official community repo |
(!) Confirm your kernel and libc version if running on significantly old systems (pre-4.0 kernels may not be supported).
Ubuntu 22.04 LTS / Debian 12
- Import GitHub CLI GPG keyring:
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
- Add the official repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \ | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
- Update and install:
sudo apt update sudo apt install gh
Verification:
gh --version
# Expected: gh version 2.46.0 (Jun 2024) or newer
Gotcha: Outdated GPG keyring errors will block installation; ensure your system clock is accurate.
Fedora 39
Fedora’s modular repo system sometimes lags behind, so prefer the upstream RPM:
sudo dnf install 'dnf-command(config-manager)'
sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
To confirm:
gh --version
Known Issue: Proxy environments may block repo import; set http_proxy
and https_proxy
as needed.
CentOS 8 Stream / RHEL 8
-
Enable EPEL—critical for dependencies:
sudo yum install epel-release
-
Add GitHub CLI repository:
sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo sudo yum install gh
Note: Without EPEL, you may see “No package gh available.” This signals missing dependencies, not a repo misconfig.
Arch Linux (2024.06)
Nothing custom—official repository package is current.
sudo pacman -Syu github-cli
Confirm with:
gh --version
Authentication: Linking gh
With Your GitHub Account
Set up once, use everywhere:
gh auth login
Choose between browser-based device authorization and SSH key-based workflows. On headless servers, use the paste-in device code method.
Contains a subtle pitfall: Multiple GitHub accounts (e.g., company and personal)? gh
maintains separate authentication contexts via gh auth login --hostname <hostname>
. Run gh auth status
to verify current context.
Usage: Typical and Less Obvious
Take a typical workflow:
gh repo clone cli/cli
cd cli
gh issue list --state open
Batch close all duplicate bugs with:
gh issue list --search "is:open label:duplicate" -L 100 | awk '{print $1}' | xargs -n 1 gh issue close
(This illustrates piping CLI output into automation—useful in housekeeping scripts.)
Non-obvious tip:
To open a PR and immediately mark it as draft (often required by team policy):
gh pr create --title "Draft: Add feature X" --draft
Troubleshooting
-
Error:
gh: command not found
even after install?
Potential cause:$PATH
not updated—check/usr/bin
or/usr/local/bin
. -
Error:
gh: cannot connect to github.com
Proxy/firewall issue.ssh: connect to host github.com port 22: Connection timed out
Set HTTP(S) proxy variables or adjust your firewall rules.
Summary
CLI integration matters: automation, speed, and less context switching. Whether you’re scripting bulk repo operations, automating releases, or just performing code review from tmux, the GitHub CLI is a foundational tool on any modern Linux workstation or build agent.
Trade-off: While gh
unlocks efficiency, some advanced repo admin functions still require web UI access or direct API calls. It's not a total replacement—but it covers 90% of daily workflow.
For deeper integration ideas (custom aliases, webhook triggers, or attaching gh
to your CI runners), skim the official docs or experiment—the utility surface is wide.
Side Note:
On some enterprise networks, SSL interception can break repo imports during install. For a workaround, specify APT::Acquire::https::Verify-Peer "false";
in /etc/apt/apt.conf.d/
. Not recommended for production, but sometimes necessary for prototyping.