GitHub CLI (gh) lets you manage GitHub repositories directly from the terminal. Clone repositories without copying URLs from your browser, create pull requests without switching windows, and review issues or trigger workflows from the command line. Ubuntu’s default gh package often lags several versions behind, missing security patches and new features. By the end of this guide, you will have the latest GitHub CLI installed from the official repository and authenticated with your GitHub account.
The GitHub CLI repository uses a universal package format that works on all current Ubuntu releases, including LTS and interim versions. Commands in this guide work identically regardless of your specific Ubuntu version.
Update Ubuntu System
Before installing new packages, update your Ubuntu packages to avoid conflicts. Run the following command to refresh your package lists and upgrade existing packages:
sudo apt update && sudo apt upgrade
Install Required Packages
GitHub CLI relies on curl for downloading the GPG keyring and ca-certificates to ensure secure HTTPS connections. Install these packages with the following command:
sudo apt install curl ca-certificates -y
Import GitHub CLI GPG Key
To verify package authenticity, import the official GitHub CLI GPG key. This key signs the packages to prevent tampering:
sudo curl -fsSLo /usr/share/keyrings/githubcli-archive-keyring.gpg https://cli.github.com/packages/githubcli-archive-keyring.gpg
This command downloads the key directly to the trusted keyring directory.
Add GitHub CLI Repository
Next, configure the repository using the recommended DEB822 .sources format. This standard ensures compatibility with modern Apt versions and keeps your sources list clean:
echo "Types: deb
URIs: https://cli.github.com/packages
Suites: stable
Components: main
Architectures: $(dpkg --print-architecture)
Signed-By: /usr/share/keyrings/githubcli-archive-keyring.gpg" | sudo tee /etc/apt/sources.list.d/github-cli.sources > /dev/null
This command creates the repository configuration file, mapping the stable suite to your system architecture.
Install GitHub CLI
Update the package index to detect the new repository, then install the gh package:
sudo apt update
sudo apt install gh -y
Verify Installation
Confirm the installation was successful by checking the installed version:
gh --version
Example output:
gh version 2.85.0 (2026-01-14) https://github.com/cli/cli/releases/tag/v2.85.0
Authenticate with GitHub
Before using the CLI, you must log in to your GitHub account. Start the authentication process with:
gh auth login
Follow the on-screen prompts to complete the setup. The CLI will ask you to select:
- Account Type: Choose
GitHub.comfor standard accounts. - Protocol: Select
HTTPSorSSHbased on your preference. If you use SSH keys, select SSH; otherwise, HTTPS is easier for beginners. - Authentication Method: Choose
Login with a web browserfor the simplest experience. The CLI will generate a one-time code to enter in your browser.
Common GitHub CLI Commands
Once authenticated, you can start using gh to manage your workflows. Here are a few essential commands:
Clone a Repository
Clone a repository directly by specifying the owner and repo name:
gh repo clone owner/repo
Manage Extensions
GitHub CLI supports extensions that add new functionality. Search for available extensions:
gh extension search
Install a useful extension, such as gh-copilot (if you have access):
gh extension install github/gh-copilot
View Issues
List the open issues for the current repository:
gh issue list
Create a Pull Request
Create a new pull request from your current branch:
gh pr create
This launches an interactive interface to set the title, body, and reviewers.
Checkout a Pull Request
To test or review someone else’s pull request locally, use the checkout command followed by the PR number:
gh pr checkout 123
Troubleshooting Common GitHub CLI Issues
If you encounter issues while using GitHub CLI, check these common solutions.
Authentication Failures
If your commands fail with permission errors, your authentication token may have expired or been revoked. Refresh your credentials without reinstalling:
gh auth refresh
Git Protocol Errors
If you encounter Permission denied (publickey) errors during git push or git clone, your CLI might be configured for SSH while you only have HTTPS access (or vice versa). Switch the protocol configuration:
# Switch to HTTPS
gh config set git_protocol https
# Or switch to SSH
gh config set git_protocol ssh
Update GitHub CLI
The APT package manager handles updates natively. To check for and apply updates to GitHub CLI:
sudo apt update
sudo apt install --only-upgrade gh
Remove GitHub CLI
If you no longer need GitHub CLI, you can remove the package and its configuration.
Remove the Package
Uninstall the gh package:
sudo apt remove gh
Remove Repository and Key
To completely clean up your system, remove the repository configuration and GPG key:
sudo rm /etc/apt/sources.list.d/github-cli.sources
sudo rm /usr/share/keyrings/githubcli-archive-keyring.gpg
Update the package list to reflect the changes:
sudo apt update
Clean Up Dependencies
Remove any unused dependencies installed with GitHub CLI:
sudo apt autoremove
Optional: Remove your local authentication and configuration data (WARNING: this cannot be undone):
rm -rf ~/.config/gh
Conclusion
You now have GitHub CLI configured with the official repository, providing access to the latest features and security updates. The gh command integrates with your existing Git workflow, enabling streamlined pull request management, issue tracking, and repository operations directly from the terminal.