GitHub CLI brings pull requests, issues, releases, and repository cloning into the terminal through the gh command. To install GitHub CLI on Ubuntu with current upstream updates, use GitHub’s official APT repository instead of relying only on Ubuntu’s default package.
Ubuntu 26.04, 24.04, and 22.04 all provide a default gh package, so sudo apt install gh works when you only need the distro package. GitHub’s repository currently provides a newer release across all three supported Ubuntu LTS versions, while core version-control tasks still depend on the standard Git package for Ubuntu.
Install GitHub CLI on Ubuntu
The official GitHub CLI repository uses a codename-neutral stable suite, so one source file works across Ubuntu 26.04, 24.04, and 22.04. Verified package candidates show why the official source is the stronger default for readers who want the latest gh release.
| Install source | Ubuntu 26.04 | Ubuntu 24.04 | Ubuntu 22.04 | Best fit |
|---|---|---|---|---|
| Ubuntu repositories | 2.46.x series | 2.45.x series | 2.4.x series | Use only when you prefer Ubuntu’s packaged version and do not need newer GitHub CLI features. |
| GitHub official APT repository | Current upstream release | Current upstream release | Current upstream release | Use for the current upstream release with normal APT updates. |
Update Ubuntu Packages
Refresh your package lists before adding the GitHub CLI repository so APT starts from current metadata.
sudo apt update && sudo apt upgrade
These commands use
sudofor system-level package and repository changes. If your account cannot use sudo yet, follow the guide to add a new user to sudoers on Ubuntu first.
Install Curl and HTTPS Certificates
Install curl for the keyring download and ca-certificates for HTTPS certificate validation. If you want a deeper command reference, the curl command guide explains the download flags used in the next step.
sudo apt install curl ca-certificates
Add the GitHub CLI Keyring
GitHub publishes a binary keyring file for the CLI repository, so download it directly instead of dearmoring an ASCII key. The -fsSLo flags make curl fail on HTTP errors, show errors when they occur, follow redirects through the URL, and write the file to the path you specify.
sudo curl -fsSLo /usr/share/keyrings/githubcli-archive-keyring.gpg https://cli.github.com/packages/githubcli-archive-keyring.gpg
Confirm the file is an OpenPGP binary keyring rather than copied HTML or ASCII armor.
file /usr/share/keyrings/githubcli-archive-keyring.gpg
Expected output begins with:
/usr/share/keyrings/githubcli-archive-keyring.gpg: OpenPGP Public Key Version 4
Add the Official GitHub CLI Repository
Create a DEB822 source file for GitHub CLI. The $(dpkg --print-architecture) part inserts your Ubuntu architecture, such as amd64 or arm64, and sudo tee writes the file with root privileges because a normal shell redirect cannot write into /etc/apt/sources.list.d/.
printf '%s\n' \
'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
Refresh APT so Ubuntu reads the new source.
sudo apt update
Relevant output includes the GitHub CLI repository:
Get:1 https://cli.github.com/packages stable InRelease [3,917 B] Get:2 https://cli.github.com/packages stable/main amd64 Packages [357 B]
Check that the GitHub repository is now the candidate source for gh.
apt-cache policy gh
The version number changes as GitHub publishes new releases, but the candidate should come from the official repository:
gh:
Installed: (none)
Candidate: 2.x.x
Version table:
2.x.x 500
500 https://cli.github.com/packages stable/main amd64 Packages
Install the GitHub CLI Package
Install the gh package from the newly added repository.
sudo apt install gh
Verify the installed GitHub CLI version.
gh --version
A repository install returns output in this format. The version and release date change as GitHub publishes new releases.
gh version 2.x.x (YYYY-MM-DD) https://github.com/cli/cli/releases/tag/v2.x.x
Authenticate GitHub CLI on Ubuntu
GitHub CLI needs an authenticated GitHub account before it can create pull requests, read private repositories, or manage issues under your identity. Start the interactive login flow from your terminal.
gh auth login
The login prompts ask for these choices:
- Account type: Choose
GitHub.comfor normal public GitHub accounts. - Git protocol: Choose
HTTPSfor the simplest setup, orSSHif your SSH keys are already configured for GitHub. - Authentication method: Choose
Login with a web browserfor the browser-based device-code flow.
Check the active login after the browser flow completes.
gh auth status
Set Up Git Credential Integration
If you selected HTTPS during login, configure Git to use GitHub CLI as the credential helper for authenticated GitHub hosts. This lets normal Git commands reuse the same account instead of prompting separately.
gh auth setup-git
Organizations that enforce SAML single sign-on may still require browser authorization for the token after login. That approval happens in GitHub, not in Ubuntu’s package manager.
Authenticate to GitHub Enterprise Server
Use the --hostname flag when your organization runs GitHub Enterprise Server instead of the public github.com service. Replace the example hostname with your enterprise instance.
gh auth login --hostname git.example.com
Switch Between GitHub CLI Accounts
GitHub CLI can store more than one account for a host. Authenticate the extra account first, then switch the active account when you move between work and personal repositories.
gh auth login
gh auth switch
Set the GitHub CLI Text Editor
GitHub CLI opens your configured editor for longer pull request descriptions, release notes, and issue text. Set an editor explicitly if the default does not match your workflow.
gh config set editor "nano"
For Visual Studio Code, use the wait flag so gh pauses until you close the editor window.
gh config set editor "code --wait"
Use Common GitHub CLI Commands
The gh command handles GitHub platform actions, while git still handles commits, pulls, pushes, branches, local history, and remotes. If your Git identity is not configured yet, set it with the Git username and email guide before creating commits.
Clone a GitHub Repository
Clone a repository by owner and repository name without copying the full web URL.
gh repo clone owner/repo
List GitHub Issues
List open issues for the repository in your current directory.
gh issue list
Create a Pull Request
Create a pull request from the current branch and follow the interactive prompts for title, body, reviewers, and base branch.
gh pr create
Check Out a Pull Request
Check out a pull request locally when you need to test or review someone else’s branch.
gh pr checkout 123
List GitHub Actions Workflows
Show the workflows configured in the current repository before running or inspecting workflow history.
gh workflow list
List GitHub Releases
List releases for the repository in your current directory when you need to check tags or published release assets from the terminal.
gh release list
Manage GitHub CLI Extensions
Extensions add subcommands to gh, but they are separate from the base GitHub CLI package. Search extensions from the terminal, then review what is already installed.
gh extension search
gh extension list
GitHub Copilot CLI is a separate extension workflow and requires Copilot access. Use the dedicated guide to install GitHub Copilot CLI on Ubuntu if that is the tool you need.
Troubleshoot GitHub CLI on Ubuntu
Fix Unable to Locate Package gh
If APT cannot find gh, the official repository was not refreshed or your source file was not written correctly.
E: Unable to locate package gh
Refresh APT and check the candidate again.
sudo apt update
apt-cache policy gh
If the official repository still does not appear, re-check /etc/apt/sources.list.d/github-cli.sources and the keyring path from the install section. Ubuntu’s default gh package also lives in Universe, so readers using only sudo apt install gh may need to enable Universe on Ubuntu first.
Refresh Expired GitHub CLI Authentication
Expired, revoked, or scope-limited tokens can make otherwise valid gh commands fail. Check your login state, then refresh the token scopes.
gh auth status
gh auth refresh
Fix SSH Public Key Errors
If clone or push operations fail with a public-key error, GitHub CLI may be set to SSH while your account only has HTTPS credentials configured.
git@github.com: Permission denied (publickey).
Switch GitHub CLI’s Git protocol to HTTPS, or set it back to SSH after you add a valid SSH key to your GitHub account.
gh config set git_protocol https
gh config set git_protocol ssh
Clear GitHub CLI Token Environment Overrides
If GH_TOKEN or GITHUB_TOKEN is set in your shell, GitHub CLI uses that environment token instead of storing browser-login credentials. Clear the token variables before running the login flow again.
To have GitHub CLI store credentials instead, first clear the value from the environment.
unset GH_TOKEN
unset GITHUB_TOKEN
gh auth login
Update GitHub CLI on Ubuntu
APT handles future GitHub CLI updates after the official repository is installed. Use --only-upgrade when you want to upgrade gh without installing it on systems where it is absent.
sudo apt update
sudo apt install --only-upgrade gh
Remove GitHub CLI from Ubuntu
Remove the gh package first. This keeps package removal separate from optional repository cleanup.
sudo apt remove gh
If you also want to stop receiving packages from GitHub’s repository, remove the source file and keyring, then refresh APT.
sudo rm -f /etc/apt/sources.list.d/github-cli.sources
sudo rm -f /usr/share/keyrings/githubcli-archive-keyring.gpg
sudo apt update
Confirm the package is no longer installed.
dpkg-query -W -f='${db:Status-Abbrev}\n' gh 2>/dev/null | grep '^ii' || echo "gh is not installed"
Expected output after removal:
gh is not installed
If APT installed Git-related packages only as dependencies for GitHub CLI, review the autoremove preview before deleting anything else. Reused systems often have unrelated autoremovable packages, so do not confirm removal until the list makes sense.
sudo apt autoremove --dry-run
The next command permanently deletes GitHub CLI authentication and configuration for the current user, including stored hosts, tokens, and account selections. Export or note anything you need before removing the directory.
rm -rf ~/.config/gh
Conclusion
GitHub CLI is available as gh from GitHub’s official APT repository, with authentication, updates, and cleanup handled from the terminal. Use it alongside Git for issues, pull requests, releases, and workflow commands; for graphical repository management, install GitHub Desktop on Ubuntu, or add Copilot-specific commands with GitHub Copilot CLI on Ubuntu.
Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>