Written and maintained by CASRAI Editorial Board
Last updated
GitHub CLI (the gh command) is installed from GitHub’s own packages: Homebrew on macOS, WinGet on Windows, or the official apt and dnf repositories on Linux. After installing, one command, gh auth login, signs you in and can create and upload the SSH key your machine needs for GitHub. The commands below follow the project’s current installation documentation, checked on 2026-10-29.
What gh is used for in research
Research code, analysis scripts, manuscripts and small datasets are often versioned on GitHub. gh brings GitHub tasks to the terminal, which matters on machines without a browser, such as a cluster login node. The project states that GitHub CLI is supported for users on GitHub.com, GitHub Enterprise Cloud and supported GitHub Enterprise Server versions, on macOS, Windows and Linux. If you are still deciding between hosting services, see Git vs GitHub vs GitLab.
Install or access (official source only)
macOS
Install with Homebrew:
brew install gh
Windows
Install with WinGet, or download the precompiled binary (MSI) from the project’s GitHub Releases page:
winget install --id GitHub.cli --source winget
The Windows installer modifies your PATH. When using Windows Terminal, you need to open a new window for the changes to take effect.
Debian, Ubuntu and Raspberry Pi OS (apt)
The project hosts signed Debian packages. Its documented install adds the signing key and repository, then installs the package:
(type -p wget >/dev/null || (sudo apt update && sudo apt install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& out=$(mktemp) && wget -nv -O$out https://cli.github.com/packages/githubcli-archive-keyring.gpg \
&& cat $out | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& sudo mkdir -p -m 755 /etc/apt/sources.list.d \
&& 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 \
&& sudo apt update \
&& sudo apt install gh -y
Fedora (dnf)
On DNF5:
sudo dnf install dnf5-plugins
sudo dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo
sudo dnf install gh
On DNF4:
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
How to install from GitHub itself
The project also publishes precompiled binaries on its GitHub Releases page, and RPM repositories for yum and zypper. Use these when no package manager above fits, for example on a managed server where you cannot add repositories.
Step-by-step: sign in and set up SSH keys for GitHub
- On Windows, open a new Windows Terminal window (a new tab is not enough) so the updated PATH is picked up.
- Run
gh auth login. It authenticates with a GitHub host, and the default host is github.com. For a different host, add--hostname, for examplegh auth login --hostname enterprise.internal. - Choose
sshas the Git protocol when asked (or pass-p ssh). The login command then detects existing SSH keys to upload and prompts to create and upload a new key if none is found. This one flow covers both how to set up an SSH key for GitHub and how to sign in. - Complete the sign-in. The default authentication mode is a web-based browser flow. Add
-c(--clipboard) to copy the one-time device code, as ingh auth login --web --clipboard.
If you do not want gh to generate or upload a key, pass --skip-ssh-key, which skips the SSH key prompt.
Creating the key yourself
GitHub’s documentation for generating a key uses the Ed25519 algorithm, with an RSA fallback for older systems:
ssh-keygen -t ed25519 -C "[email protected]"
ssh-keygen -t rsa -b 4096 -C "[email protected]"
To load the key into the SSH agent, start the agent with eval "$(ssh-agent -s)" and then:
- macOS:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519 - Linux:
ssh-add ~/.ssh/id_ed25519 - Windows (PowerShell):
Start-Service ssh-agent, thenssh-add c:/Users/YOU/.ssh/id_ed25519with your own user name
Servers, HPC and CI without a browser
Use gh auth login --with-token < mytoken.txt, which reads a personal access token (classic) from standard input. The minimum scopes are repo, read:org and gist. For a fine-grained personal access token, the manual says to favour setting the GH_TOKEN environment variable instead. Tokens are stored in the system credential store; if none is available, gh falls back to a plain text file.
Output and how to read it
Once gh auth login completes with ssh selected, any later git clone over SSH can use the uploaded key. For reproducible work, record the Git protocol and host in your project’s README so collaborators set up the same way, and pair it with a locked environment such as renv for R or a shared conda environment.
Troubleshooting
gh: command not found after installing on Windows
The installer changes PATH, so open a new Windows Terminal window before trying again.
Installed gh as a snap
The project’s Linux documentation recommends never installing gh as a snap. Remove the snap and use the apt or dnf route above.
Token rejected or commands fail on permissions
Check the token has at least the repo, read:org and gist scopes, or log in again with -s (--scopes) to request the scopes you need.
Distribution packages
Packages from Arch (sudo pacman -S github-cli), Alpine (apk add github-cli), Scoop, Chocolatey, Conda and Nix are community-maintained, not GitHub-supported. Prefer the official routes when you need support.
Alternatives: other install routes
| Platform | Official route | Command |
|---|---|---|
| macOS | Homebrew | brew install gh |
| Windows | WinGet | winget install --id GitHub.cli --source winget |
| Debian, Ubuntu | apt repository | sudo apt install gh -y (after adding the repository) |
| Fedora | dnf repository | sudo dnf install gh (after adding the repository) |
| Any | Precompiled binaries | Download from GitHub Releases |
FAQ
How do I install GitHub CLI?
Use Homebrew (brew install gh) on macOS, WinGet on Windows, or the official apt or dnf repository on Linux, then run gh auth login.
How do I set up SSH keys for GitHub?
Run gh auth login and choose ssh. The command detects existing keys to upload and offers to create and upload a new one if none is found. Alternatively generate one with ssh-keygen -t ed25519 -C "[email protected]" and add it to the SSH agent.
How do I install from GitHub?
For gh, download a precompiled binary from the project’s GitHub Releases page, or use an official package repository.
Sources (official documentation)
- GitHub CLI README, installation, https://github.com/cli/cli#installation (checked 2026-10-29)
- Installing gh on Linux and BSD, https://github.com/cli/cli/blob/trunk/docs/install_linux.md (checked 2026-10-29)
- Installing gh on Windows, https://github.com/cli/cli/blob/trunk/docs/install_windows.md (checked 2026-10-29)
- gh auth login manual, https://cli.github.com/manual/gh_auth_login (checked 2026-10-29)
- GitHub Docs: generating a new SSH key and adding it to the ssh-agent, https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent (checked 2026-10-29)








