{"meta":{"title":"安装 GitHub Copilot CLI","intro":"了解如何安装 Copilot CLI ，以便直接从命令行使用 Copilot 。","product":"GitHub Copilot","breadcrumbs":[{"href":"/zh/copilot","title":"GitHub Copilot"},{"href":"/zh/copilot/how-tos","title":"操作方法"},{"href":"/zh/copilot/how-tos/copilot-cli","title":"Copilot CLI"},{"href":"/zh/copilot/how-tos/copilot-cli/set-up-copilot-cli","title":"设置 Copilot CLI"},{"href":"/zh/copilot/how-tos/copilot-cli/set-up-copilot-cli/install-copilot-cli","title":"安装 Copilot CLI"}],"documentType":"article"},"body":"# 安装 GitHub Copilot CLI\n\n了解如何安装 Copilot CLI ，以便直接从命令行使用 Copilot 。\n\n若要在安装之前了解 Copilot CLI 相关信息，请参阅 [关于 GitHub Copilot CLI](/zh/copilot/concepts/agents/about-copilot-cli)。\n\n## 先决条件\n\n* **活动 GitHub Copilot 订阅**。 查看 [Copilot 计划](https://github.com/features/copilot/plans?ref_product=copilot\\&ref_type=engagement\\&ref_style=text)。\n* （Windows） **PowerShell** v6 或更高版本\n\n如果您通过组织或企业访问 GitHub Copilot 但组织所有者或企业管理员在组织或企业设置中禁用了 Copilot CLI ，则您无法使用 Copilot CLI 。 请参阅 [管理组织中GitHub Copilot的策略和功能](/zh/copilot/managing-copilot/managing-github-copilot-in-your-organization/managing-github-copilot-features-in-your-organization/managing-policies-for-copilot-in-your-organization)。\n\n## 安装或更新 Copilot CLI\n\n可以使用 WinGet（Windows）、Homebrew（macOS 和 Linux）、npm（所有平台）或安装脚本（macOS 和 Linux）安装 Copilot CLI。\n\n### 使用 npm 安装（所有平台）\n\n先决条件： Node.js 22 或更高版本.\n\n```shell copy\nnpm install -g @github/copilot\n```\n\n> \\[!NOTE]\n> 如果在`ignore-scripts=true`文件中有`~/.npmrc`，则必须使用以下命令：\n>\n> ```shell copy\n> npm_config_ignore_scripts=false npm install -g @github/copilot\n> ```\n\n安装预发行版版本：\n\n```shell copy\nnpm install -g @github/copilot@prerelease\n```\n\n### 使用 WinGet 进行安装（Windows）\n\n```powershell copy\nwinget install GitHub.Copilot\n```\n\n安装预发行版版本：\n\n```powershell copy\nwinget install GitHub.Copilot.Prerelease\n```\n\n### 使用 Homebrew 进行安装（macOS 和 Linux）\n\n```shell copy\nbrew install copilot-cli\n```\n\n安装预发行版版本：\n\n```shell copy\nbrew install copilot-cli@prerelease\n```\n\n### 使用安装脚本进行安装（macOS 和 Linux）\n\n```shell copy\ncurl -fsSL https://gh.io/copilot-install | bash\n```\n\n或者：\n\n```shell copy\nwget -qO- https://gh.io/copilot-install | bash\n```\n\n若要以根身份运行并安装到 `/usr/local/bin`，请使用 `| sudo bash`。\n\n若要安装到自定义目录，请设置 `PREFIX` 环境变量。 运行时，如果以根用户身份运行，默认为 `/usr/local`；如果以非根用户身份运行，默认为 `$HOME/.local`。\n\n若要安装特定版本，请设置 `VERSION` 环境变量。 默认为最新版本。\n\n例如，若要将版本 `v0.0.369` 安装到自定义目录，\n\n```shell copy\ncurl -fsSL https://gh.io/copilot-install | VERSION=\"v0.0.369\" PREFIX=\"$HOME/custom\" bash\n```\n\n### 从 GitHub.com\n\n下载\n\n可以直接从[存储库`copilot-cli`下载可执行文件](https://github.com/github/copilot-cli/releases/)。\n\n下载平台的可执行文件，将其解压缩并运行。\n\n## 使用 Copilot CLI 进行身份验证\n\n首次启动时，如果当前未登录 GitHub，系统会提示你使用 `/login` 斜杠命令。 输入此命令并按照屏幕说明完成身份验证流程。 有关身份验证过程的详细信息，请参阅 [对 GitHub Copilot CLI 进行身份验证](/zh/copilot/how-tos/copilot-cli/set-up-copilot-cli/authenticate-copilot-cli)。\n\n### 使用personal access token进行身份验证\n\n你也可使用已启用“Copilot 请求”权限的 fine-grained personal access token 进行身份验证。\n\n1. 访问 [Fine-grained personal access tokens](https://github.com/settings/personal-access-tokens/new)。\n2. 在“权限”下，单击“ **添加权限** ”，然后选择“ **Copilot 请求**”。\n3. 单击“生成令牌”。\\*\\*\\*\\*\n4. 在终端或环境配置中导出令牌。 使用`COPILOT_GITHUB_TOKEN`、`GH_TOKEN`或`GITHUB_TOKEN`环境变量（按优先级顺序）。\n\n## 后续步骤\n\n现在可以从命令行使用 Copilot 。 请参阅 [使用 GitHub Copilot CLI](/zh/copilot/how-tos/use-copilot-agents/use-copilot-cli)。"}