How to Install GitHub CLI on Ubuntu (26.04, 24.04, 22.04)

Last updated January 24, 2026 6:38 pm Joshua James 5 min read

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.com for standard accounts.
  • Protocol: Select HTTPS or SSH based on your preference. If you use SSH keys, select SSH; otherwise, HTTPS is easier for beginners.
  • Authentication Method: Choose Login with a web browser for 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

Common Questions

Why should I use the GitHub CLI repository instead of the default Ubuntu package?

Ubuntu’s default repositories often contain outdated versions of the CLI. Using the official repository ensures you have the latest features, immediate bug fixes, and access to new commands as soon as they are released.

Can I manage multiple GitHub accounts on a single Ubuntu system?

Yes. You can authenticate multiple accounts using gh auth login and toggle between them using gh auth switch. This allows you to manage personal and work profiles seamlessly without manual SSH key configurations.

Does GitHub CLI replace the standard Git command?

No. gh is designed for GitHub specific platform tasks like managing pull requests, issues, and releases. You still need the standard git command for core version control operations like committing, pushing, and merging local history.

How do I change the default text editor for pull request descriptions?

GitHub CLI uses your system’s default editor (usually Nano or Vim). You can set your preferred editor specifically for the CLI by running gh config set editor "code --wait" (for VS Code) or your editor of choice.

Can I use GitHub CLI with GitHub Enterprise Server?

Yes. Use the --hostname flag when authenticating. For example: gh auth login --hostname git.example.com. This configures the CLI to interact with your private instance instead of the public GitHub.com.

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.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags:

You type Result
<code>command</code> command
<pre>block of code</pre> code block
<strong>bold</strong> bold
<em>italic</em> italic
<a href="URL">link</a> link
<blockquote>quote</blockquote> quote block

Leave a Comment

We read and reply to every comment — let us know how we can help or improve this guide.

Let us know you are human: