How To

Install GitHub CLI (gh) on Linux, macOS, and Windows

GitHub CLI (gh) is the official command-line tool from GitHub that brings pull requests, issues, repositories, gists, and other GitHub features directly into your terminal. Instead of switching between your browser and terminal, you can manage your entire GitHub workflow from the command line. This guide covers installing GitHub CLI on Ubuntu 24.04, Debian 13, RHEL 10, Rocky Linux 10, Fedora 42, macOS, and Windows, plus authentication and everyday usage.

Original content from computingforgeeks.com - post 57388

At the time of writing, the latest stable release is gh v2.88.1 (March 2026). GitHub CLI replaces the older hub command-line wrapper and is actively maintained by GitHub.

Prerequisites

Before you begin, make sure you have:

  • A GitHub account
  • A Linux, macOS, or Windows machine with internet access
  • sudo or administrator privileges for package installation
  • Git installed on your system

Step 1: Install GitHub CLI on Ubuntu / Debian

GitHub provides an official APT repository for Ubuntu and Debian systems. This method works on Ubuntu 24.04, Ubuntu 22.04, Debian 13, Debian 12, and related derivatives like Linux Mint.

First, install the required dependencies and add the GitHub CLI repository:

sudo apt update
sudo apt install -y curl gpg

sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null

Now update the package index and install the gh package:

sudo apt update
sudo apt install -y gh

Confirm the installation by checking the version:

gh --version

You should see output similar to:

gh version 2.88.1 (2026-03-12)
https://github.com/cli/cli/releases/tag/v2.88.1

To upgrade GitHub CLI later, run a standard apt upgrade:

sudo apt update && sudo apt upgrade gh

Step 2: Install GitHub CLI on RHEL / Rocky Linux / Fedora

For RPM-based distributions including RHEL 10, Rocky Linux 10, AlmaLinux 10, and Fedora 42, GitHub maintains a DNF/YUM repository.

Add the official GitHub CLI repository and install:

sudo dnf install -y 'dnf-command(config-manager)'
sudo dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install -y gh

On older RHEL/CentOS systems that use yum, the commands are the same but use yum instead of dnf.

Verify the installation:

gh --version

Expected output:

gh version 2.88.1 (2026-03-12)
https://github.com/cli/cli/releases/tag/v2.88.1

Future upgrades happen automatically through dnf upgrade gh.

Step 3: Install GitHub CLI on macOS

On macOS, the easiest way to install GitHub CLI is through Homebrew. If you don’t have Homebrew installed, you can also download a binary from the GitHub CLI releases page.

Install using Homebrew:

brew install gh

Verify the installed version:

gh --version

To upgrade later:

brew upgrade gh

Step 4: Install GitHub CLI on Windows

On Windows, you can install GitHub CLI using either winget (built into Windows 11 and recent Windows 10 builds) or Chocolatey.

Option A: Install with winget

Open PowerShell or Command Prompt and run:

winget install --id GitHub.cli

After installation, restart your terminal session so the gh command becomes available in your PATH.

Option B: Install with Chocolatey

If you use Chocolatey as your Windows package manager, install with:

choco install gh

Option C: Install with Scoop

Scoop users can install GitHub CLI from the main bucket:

scoop install gh

Regardless of installation method, verify by opening a new terminal and running:

gh --version

Step 5: Authenticate with GitHub

After installing GitHub CLI, you need to authenticate before you can interact with GitHub. The gh auth login command walks you through an interactive flow.

Start the authentication process:

gh auth login

The CLI will prompt you to choose:

  1. Where to authenticate – Choose GitHub.com or GitHub Enterprise Server
  2. Preferred protocol – HTTPS or SSH
  3. Authentication method – Browser-based login (recommended) or paste a personal access token

For browser-based login, gh displays a one-time code. You open the URL shown in the terminal, enter the code, and authorize the CLI. This is the simplest approach and avoids handling tokens manually.

Once authenticated, verify your login status:

gh auth status

The output confirms which account is logged in and the active protocol:

github.com
  ✓ Logged in to github.com account yourname (keyring)
  - Active account: true
  - Git operations protocol: https
  - Token: gho_************************************
  - Token scopes: 'gist', 'read:org', 'repo', 'workflow'

If you need to authenticate with a personal access token instead (useful for CI/CD pipelines or automation), you can pass it directly:

echo "YOUR_TOKEN" | gh auth login --with-token

To log out or switch accounts later:

gh auth logout
gh auth login

Step 6: Common gh CLI Usage

With GitHub CLI installed and authenticated, here are the most common workflows you will use daily. The official gh CLI manual covers every command in detail.

Working with Repositories

Clone a repository directly using the owner/repo shorthand instead of typing full URLs:

gh repo clone owner/repository-name

Create a new repository interactively or with flags:

gh repo create my-project --public --clone
gh repo create my-private-app --private --clone

Fork and clone a repository in one step:

gh repo fork owner/repository-name --clone

View repository details from inside a cloned repo:

gh repo view

Managing Pull Requests

Pull request management is where gh saves the most time. You can create, review, merge, and check out PRs without leaving the terminal.

Create a pull request from your current branch:

gh pr create --title "Add user authentication" --body "Implements JWT-based auth"

List open pull requests in the current repository:

gh pr list

Check out a pull request locally for testing:

gh pr checkout 42

Review and merge a pull request:

gh pr review 42 --approve
gh pr merge 42 --squash

Working with Issues

Create, list, and manage issues directly from the command line:

gh issue create --title "Fix login timeout" --body "Login times out after 5 seconds on slow connections"
gh issue list
gh issue view 15
gh issue close 15

Managing Gists

Create gists from files or standard input:

gh gist create myfile.py --public --desc "Python helper script"
gh gist list
gh gist view GIST_ID

Checking Workflow Runs

GitHub Actions workflows can be monitored and triggered from the CLI:

gh run list
gh run view 123456789
gh run watch 123456789
gh workflow run deploy.yml

Essential gh CLI Commands Reference

The table below summarizes the most commonly used GitHub CLI commands for quick reference.

CommandDescription
gh auth loginAuthenticate with GitHub
gh auth statusCheck authentication status
gh repo clone owner/repoClone a repository
gh repo create nameCreate a new repository
gh repo fork owner/repoFork a repository
gh pr createCreate a pull request
gh pr listList open pull requests
gh pr checkout NUMCheck out a PR locally
gh pr merge NUMMerge a pull request
gh pr diff NUMView a PR diff in terminal
gh issue createCreate a new issue
gh issue listList repository issues
gh issue close NUMClose an issue
gh gist create FILECreate a gist from a file
gh run listList recent workflow runs
gh run watch NUMWatch a workflow run live
gh workflow run FILETrigger a workflow manually
gh release create TAGCreate a new release
gh api ENDPOINTMake authenticated API calls
gh ssh-key add FILEAdd an SSH key to your account

Conclusion

GitHub CLI brings your full GitHub workflow into the terminal. You can manage repositories, pull requests, issues, gists, and Actions runs without opening a browser. The authentication system handles tokens securely, and the command structure is consistent and easy to learn.

If you work with Visual Studio Code or any terminal-based editor, pairing it with gh gives you a fast, keyboard-driven development workflow. For auditing secrets in your repositories, consider using Gitleaks to audit your Git repos. If you are hosting your own Git service, check out our guides on installing Gitea on Ubuntu or GitLab CE on CentOS/Fedora.

Related Articles

AlmaLinux Install Java 21 LTS (OpenJDK 21) on AlmaLinux | CentOS | RHEL 10 Programming Install and Use Node.js on Windows 11 / Windows 10 Programming Install Swift Programming Language on Ubuntu 24.04 Debian How To Install and Use Solidity on Ubuntu / Debian

Leave a Comment

Press ESC to close