# 使用 Homebrew, chocolatey, apt, dnf, MacPorts, Nix, zypper, scoop, winget 安装 gh

查看 gh 的安装路径、可执行文件、元数据以及面向 AI 代理工作流的安全说明。

## 安装

```sh
sudo av install brew:gh
```

## 代理安全回答

gh is the GitHub control-plane CLI for repositories, releases, issues, and authenticated developer state.

- **凭据访问:** Reads GitHub CLI tokens and can print or use them for API calls.
- **远程变更:** Can modify repositories, pull requests, releases, secrets, and organization state.
- **发布/制品风险:** Can create releases, upload assets, and trigger release automation.
- **推荐控制:** Use GitHub token protection plus approval gates for write and token-display commands.
- **代理使用指南:** Permit status and read-only queries; require approval for token output, release creation, repo writes, and workflow dispatch.

其他安装命令:

### macOS

- Homebrew (100%):

```sh
brew install gh
```

  证据: local Homebrew formula metadata

- MacPorts (94%):

```sh
sudo port install gh
```

  证据: MacPorts ports tree: devel/gh/Portfile from https://api.github.com/repos/macports/macports-ports/git/trees/master?recursive=1

### Linux

- Debian apt (92%):

```sh
sudo apt install gh
```

  证据: Debian stable package indexes: gh from https://deb.debian.org/debian/dists/stable/main/binary-amd64/Packages.xz

- dnf (92%):

```sh
sudo dnf install gh
```

  证据: Fedora Rawhide package metadata: gh from https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Everything/x86_64/os/repodata/07190dc5ae9f35ae73866675fed6d95fe6e8d9fe22c9d7cdf85862cb2ed24a4c-primary.xml.zst

- Nix (92%):

```sh
nix profile install nixpkgs#gh
```

  证据: nixpkgs package indexes: pkgs/by-name/gh/gh/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1

- zypper (92%):

```sh
sudo zypper install gh
```

  证据: openSUSE Tumbleweed package metadata: gh from https://download.opensuse.org/tumbleweed/repo/oss/repodata/50b07339cb64c8ed4091bdbabddadc1ff5737b090e478818a195b40d8a3292861a879139b4a3987c31109699fde9fbf4a716367ddf4eef77da75f96e3193d6ed-primary.xml.zst

### Windows

- Chocolatey (92%):

```sh
choco install gh
```

  证据: Chocolatey community package catalog: gh from http://community.chocolatey.org/api/v2/Packages?$filter=IsLatestVersion&$select=Id&$top=1000&$skiptoken='11','fusioninventory-agent'

- Scoop (92%):

```sh
scoop install main/gh
```

  证据: Scoop official bucket manifest trees: bucket/gh.json from https://api.github.com/repos/ScoopInstaller/Main/git/trees/master?recursive=1

- winget (92%):

```sh
winget install --id GitHub.cli -e
```

  证据: Windows Package Manager source index: GitHub.cli from https://cdn.winget.microsoft.com/cache/source.msix

## 软件包事实

- **软件包键:** brew:gh
- **软件包管理器:** Homebrew
- **版本:** 2.97.0
- **来源摘要:** GitHub command-line tool
- **主页:** <https://cli.github.com/>
- **仓库:** <https://github.com/cli/cli>
- **最后更新:** 2026-07-31T05:32:54Z
- **已生成:** 2026-08-03T19:37:03+00:00

## 可执行文件

- gh (别名)

## 安装行为

- Bottle: 不可用

## 版本和新鲜度

- 页面生成时间: 2026-08-03
- 管理器版本: 2.97.0
## 项目历史与用法

GitHub CLI, invoked as `gh`, is GitHub's official command-line tool for working with pull requests, issues, repositories, releases, Actions, authentication, and GitHub API data from a terminal.

### 项目历史

GitHub created the cli/cli repository in October 2019 and opened the project as a new official CLI distinct from the older community `hub` tool. GitHub announced the beta in February 2020 and released GitHub CLI 1.0 in September 2020.

The README frames `gh` as a standalone tool that brings GitHub concepts next to `git` and source code work. The project grew into a cross-platform Go CLI with first-party manuals, release binaries, package repositories, GitHub Enterprise support, extension support, API helpers, and later supply-chain features such as build provenance attestations for release artifacts.

### 采用历史

GitHub CLI has broad adoption because it is distributed through GitHub's own package repositories and release binaries, package managers such as Homebrew and WinGet, and GitHub-hosted Actions runner images. Its first-party status made it a standard automation interface for GitHub workflows in shells and CI jobs.

### 使用方式

Practitioners use `gh` to create and review pull requests, triage issues, clone and browse repositories, trigger or inspect Actions workflows, manage releases and gists, authenticate to GitHub hosts, call the GitHub API, and script repository operations without leaving the command line.

### 为什么软件包爱好者会关心

For package and automation ecosystems, `gh` is important because it gives GitHub an official, versioned executable surface. Package maintainers can depend on consistent commands across macOS, Linux, and Windows, while CI authors can use a preinstalled or easily installed binary instead of hand-rolling API calls.

### 时间线

- 2019: The cli/cli repository was created.
- 2020: GitHub announced GitHub CLI beta.
- 2020: GitHub CLI 1.0.0 was published.
- 2024: The README records release build provenance attestations beginning with version 2.50.0.

### Related projects

- The README compares GitHub CLI with `hub`, noting that `hub` behaves as a proxy to `git` while `gh` is a standalone tool for GitHub workflows.

### 来源

- <https://api.github.com/repos/cli/cli>
- <https://api.github.com/repos/cli/cli/releases>
- <https://cli.github.com/manual/gh>
- <https://docs.github.com/en/github-cli/github-cli/about-github-cli>
- <https://formulae.brew.sh/formula/gh>
- <https://github.blog/2020-02-12-supercharge-your-command-line-experience-github-cli-is-now-in-beta/>
- <https://github.blog/2020-09-17-github-cli-1-0-is-now-available/>
- <https://github.com/cli/cli>
- <https://raw.githubusercontent.com/cli/cli/trunk/README.md>


## 安全说明

broad networked developer tool.

- **Geiger 风险:** blue / 高
- broad networked developer tool
- **审批门规则:** 7


## Configuration and credential file locations

These source-backed paths show where this package keeps local settings or durable credentials. Automic Vault can use them as review targets for secret scanning, migration, and command approval.


## Configuration files

- Unix: $XDG_CONFIG_HOME/gh/config.yml, ~/.config/gh/config.yml
- Windows: %AppData%\GitHub CLI\config.yml

## Credential files

- Unix: $XDG_CONFIG_HOME/gh/hosts.yml, ~/.config/gh/hosts.yml
- Windows: %AppData%\GitHub CLI\hosts.yml
## 其他软件包管理器记录

- Debian apt - gh - 2.46.0-3: normalized package name match | Debian stable package indexes: gh from https://deb.debian.org/debian/dists/stable/main/binary-amd64/Packages.xz | GitHub CLI, GitHub’s official command line tool | https://cli.github.com/
- Nix - gh: normalized package name match | nixpkgs package indexes: pkgs/by-name/gh/gh/package.nix from https://api.github.com/repos/NixOS/nixpkgs/git/trees/master?recursive=1
- Ubuntu apt - gh - 2.45.0-1build1: normalized package name match | Ubuntu 24.04 LTS package indexes: gh from https://archive.ubuntu.com/ubuntu/dists/noble/universe/binary-amd64/Packages.gz | GitHub CLI, GitHub’s official command line tool | https://cli.github.com/
- dnf - gh - 2.97.0-1.fc45: normalized package name match | Fedora Rawhide package metadata: gh from https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Everything/x86_64/os/repodata/07190dc5ae9f35ae73866675fed6d95fe6e8d9fe22c9d7cdf85862cb2ed24a4c-primary.xml.zst | GitHub's official command line tool | https://github.com/cli/cli
- zypper - gh - 2.96.0-2.2: normalized package name match | openSUSE Tumbleweed package metadata: gh from https://download.opensuse.org/tumbleweed/repo/oss/repodata/50b07339cb64c8ed4091bdbabddadc1ff5737b090e478818a195b40d8a3292861a879139b4a3987c31109699fde9fbf4a716367ddf4eef77da75f96e3193d6ed-primary.xml.zst | The official CLI for GitHub | https://cli.github.com/
- zypper - gh-bash-completion - 2.96.0-2.2: normalized package name match | openSUSE Tumbleweed package metadata: gh-bash-completion from https://download.opensuse.org/tumbleweed/repo/oss/repodata/50b07339cb64c8ed4091bdbabddadc1ff5737b090e478818a195b40d8a3292861a879139b4a3987c31109699fde9fbf4a716367ddf4eef77da75f96e3193d6ed-primary.xml.zst | Bash Completion for gh | https://cli.github.com/
- zypper - gh-fish-completion - 2.96.0-2.2: normalized package name match | openSUSE Tumbleweed package metadata: gh-fish-completion from https://download.opensuse.org/tumbleweed/repo/oss/repodata/50b07339cb64c8ed4091bdbabddadc1ff5737b090e478818a195b40d8a3292861a879139b4a3987c31109699fde9fbf4a716367ddf4eef77da75f96e3193d6ed-primary.xml.zst | Fish completion for gh | https://cli.github.com/
- zypper - gh-zsh-completion - 2.96.0-2.2: normalized package name match | openSUSE Tumbleweed package metadata: gh-zsh-completion from https://download.opensuse.org/tumbleweed/repo/oss/repodata/50b07339cb64c8ed4091bdbabddadc1ff5737b090e478818a195b40d8a3292861a879139b4a3987c31109699fde9fbf4a716367ddf4eef77da75f96e3193d6ed-primary.xml.zst | ZSH Completion for gh | https://cli.github.com/
- MacPorts - gh: normalized package name match | MacPorts ports tree: devel/gh/Portfile from https://api.github.com/repos/macports/macports-ports/git/trees/master?recursive=1
- Chocolatey - gh: normalized package name match | Chocolatey community package catalog: gh from http://community.chocolatey.org/api/v2/Packages?$filter=IsLatestVersion&$select=Id&$top=1000&$skiptoken='11','fusioninventory-agent'
- Scoop - main/gh: normalized package name match | Scoop official bucket manifest trees: bucket/gh.json from https://api.github.com/repos/ScoopInstaller/Main/git/trees/master?recursive=1
- winget - GitHub.cli: normalized package name match | Windows Package Manager source index: GitHub.cli from https://cdn.winget.microsoft.com/cache/source.msix


## Combined YAML source

View the package source record on GitHub. [combined/gh.yml](https://github.com/mxcl/pkgdb/blob/main/combined/gh.yml)


## 来源

- pkg.so package database
- Geiger risk classifier
- approval-gate seed metadata
- curated configuration and credential file locations
- curated package history
- pkgdb category and tag curation
- external package-manager database matches
- cross-ecosystem install command graph
- curated agent safety answer
