google-gemini / gemini-cli

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Note Unpaid tier and Google One users: Gemini CLI was replaced by Antigravity CLI on June 18th, 2026. To learn more, see our blog post. Gemini CLI has not been optimized for Gemini 4 Argon. To use Gemini 4 Argon, please use Antigravity. Gemini CLI Note Gemini CLI is not optimized for the latest Gemini models. For the best coding experience with Gemini models use Antigravity CLI Gemini CLI is an open-source AI agent that brings the power of Gemini directly into your terminal. It provides lightweight access to Gemini, giving you the most direct path from your prompt to our model. Learn all about Gemini CLI in our documentation.

针对非付费层级和 Google One 用户请注意:Gemini CLI 已于 2026 年 6 月 18 日被 Antigravity CLI 取代。欲了解更多信息,请参阅我们的博客文章。Gemini CLI 未针对 Gemini 4 Argon 进行优化。如需使用 Gemini 4 Argon,请使用 Antigravity。Gemini CLI 注意事项:Gemini CLI 未针对最新的 Gemini 模型进行优化。若要获得使用 Gemini 模型的最佳编码体验,请使用 Antigravity CLI。Gemini CLI 是一个开源 AI 代理,可将 Gemini 的强大功能直接引入您的终端。它提供了对 Gemini 的轻量级访问,为您提供从提示词到模型的最直接路径。请在我们的文档中了解有关 Gemini CLI 的所有信息。

📦 Installation See Gemini CLI installation, execution, and releases for recommended system specifications and a detailed installation guide. Quick Install Run instantly with npx # Using npx (no installation required) npx @google/gemini-cli Install globally with npm npm install -g @google/gemini-cli Install globally with Homebrew (macOS/Linux) brew install gemini-cli Install globally with MacPorts (macOS) sudo port install gemini-cli Install with Anaconda (for restricted environments) # Create and activate a new environment conda create -y -n gemini_env -c conda-forge nodejs conda activate gemini_env # Install Gemini CLI globally via npm (inside the environment) npm install -g @google/gemini-cli

📦 安装:请参阅 Gemini CLI 的安装、执行和发布说明,以获取推荐的系统规格和详细的安装指南。快速安装:使用 npx 立即运行 # 使用 npx(无需安装)npx @google/gemini-cli;使用 npm 全局安装 npm install -g @google/gemini-cli;使用 Homebrew 全局安装(macOS/Linux)brew install gemini-cli;使用 MacPorts 全局安装(macOS)sudo port install gemini-cli;使用 Anaconda 安装(适用于受限环境)# 创建并激活新环境 conda create -y -n gemini_env -c conda-forge nodejs conda activate gemini_env # 在环境中通过 npm 全局安装 Gemini CLI npm install -g @google/gemini-cli

Release Channels See Releases for more details. Preview New preview releases will be published each week at UTC 23:59 on Tuesdays. These releases will not have been fully vetted and may contain regressions or other outstanding issues. Please help us test and install with preview tag. npm install -g @google/gemini-cli@preview Stable New stable releases will be published each week at UTC 20:00 on Tuesdays, this will be the full promotion of last week’s preview release + any bug fixes and validations. Use latest tag. npm install -g @google/gemini-cli@latest Nightly New releases will be published each day at UTC 00:00. This will be all changes from the main branch as represented at time of release. It should be assumed there are pending validations and issues. Use nightly tag. npm install -g @google/gemini-cli@nightly

发布渠道:有关更多详细信息,请参阅“发布”。预览版:新的预览版本将于每周二 UTC 时间 23:59 发布。这些版本未经全面审查,可能包含回归问题或其他未解决的问题。请帮助我们测试并使用 preview 标签进行安装:npm install -g @google/gemini-cli@preview。稳定版:新的稳定版本将于每周二 UTC 时间 20:00 发布,这将是上周预览版本的全面升级,并包含任何错误修复和验证。请使用 latest 标签:npm install -g @google/gemini-cli@latest。每日构建版:新的版本将于每天 UTC 时间 00:00 发布。这将包含发布时主分支的所有更改。应假设存在待处理的验证和问题。请使用 nightly 标签:npm install -g @google/gemini-cli@nightly。

📋 Key Features Code Understanding & Generation Query and edit large codebases Generate new apps from PDFs, images, or sketches using multimodal capabilities Debug issues and troubleshoot with natural language Automation & Integration Automate operational tasks like querying pull requests or handling complex rebases Use MCP servers to connect new capabilities, including media generation with Imagen, Veo or Lyria Run non-interactively in scripts for workflow automation

📋 关键功能:代码理解与生成:查询和编辑大型代码库;使用多模态功能从 PDF、图像或草图生成新应用;使用自然语言调试问题和进行故障排除。自动化与集成:自动化操作任务,例如查询拉取请求或处理复杂的变基(rebase);使用 MCP 服务器连接新功能,包括使用 Imagen、Veo 或 Lyria 进行媒体生成;在脚本中以非交互方式运行以实现工作流自动化。

🔐 Authentication Options Choose the authentication method that best fits your needs: Option 1: Sign in with Google (OAuth login using your Google Account) When using a paid Code Assist License from your organization, remember to set the Google Cloud Project # Set your Google Cloud Project export GOOGLE_CLOUD_PROJECT=“YOUR_PROJECT_ID” gemini Option 2: Gemini API Key ✨ Best for: Developers who need specific model control or paid tier access Benefits: Model selection: Choose specific Gemini models Usage-based billing: Upgrade for higher limits when needed # Get your key from https://aistudio.google.com/apikey export GEMINI_API_KEY=“YOUR_API_KEY” gemini Option 3: Vertex AI ✨ Best for: Enterprise teams and production workloads Benefits: Enterprise features: Advanced security and compliance Scalable: Higher rate limits with billing account Integration: Works with existing Google Cloud infrastructure # Get your key from Google Cloud Console export GOOGLE_API_KEY=“YOUR_API_KEY” export GOOGLE_GENAI_USE_VERTEXAI=true gemini For Google Workspace accounts and other authentication methods, see the authentication guide.

🔐 身份验证选项:选择最适合您需求的身份验证方法:选项 1:使用 Google 登录(使用您的 Google 帐户进行 OAuth 登录)。当使用组织提供的付费 Code Assist 许可证时,请记住设置 Google Cloud 项目 # 设置您的 Google Cloud 项目 export GOOGLE_CLOUD_PROJECT=“YOUR_PROJECT_ID” gemini。选项 2:Gemini API 密钥 ✨ 最适合:需要特定模型控制或付费层级访问权限的开发者。优点:模型选择:选择特定的 Gemini 模型;基于用量的计费:在需要时升级以获得更高的限额 # 从 https://aistudio.google.com/apikey 获取您的密钥 export GEMINI_API_KEY=“YOUR_API_KEY” gemini。选项 3:Vertex AI ✨ 最适合:企业团队和生产工作负载。优点:企业功能:高级安全性和合规性;可扩展:通过计费帐户获得更高的速率限制;集成:与现有的 Google Cloud 基础架构配合使用 # 从 Google Cloud 控制台获取您的密钥 export GOOGLE_API_KEY=“YOUR_API_KEY” export GOOGLE_GENAI_USE_VERTEXAI=true gemini。对于 Google Workspace 帐户和其他身份验证方法,请参阅身份验证指南。

🚀 Getting Started Note Gemini CLI is not optimized for the latest Gemini models. For the best coding experience with Gemini models use Antigravity CLI Basic Usage Start in current directory gemini Include multiple directories gemini —include-directories ../lib,../docs Use specific model gemini -m gemini-2.5-flash Non-interactive mode for scripts Get a simple text response: gemini -p “Explain the architecture of this codebase” For more advanced scripting, including how to parse JSON and handle errors, use the —output-format json flag to get structured output: gemini -p “Explain the architecture of this codebase” —output-format json For real-time event streaming (useful for monitoring long-running operations), use —output-format stream-json to get newline-delimited JSON events: gemini -p “Run tests and deploy” —output-format stream-json

🚀 入门:注意:Gemini CLI 未针对最新的 Gemini 模型进行优化。若要获得使用 Gemini 模型的最佳编码体验,请使用 Antigravity CLI。基本用法:在当前目录启动 gemini;包含多个目录 gemini —include-directories ../lib,../docs;使用特定模型 gemini -m gemini-2.5-flash。脚本的非交互模式:获取简单的文本响应:gemini -p “Explain the architecture of this codebase”。对于更高级的脚本编写(包括如何解析 JSON 和处理错误),请使用 —output-format json 标志以获取结构化输出:gemini -p “Explain the architecture of this codebase” —output-format json。对于实时事件流(适用于监控长时间运行的操作),请使用 —output-format stream-json 以获取换行符分隔的 JSON 事件:gemini -p “Run tests and deploy” —output-format stream-json。

Quick Examples Start a new project cd new-project/ gemini > Write me a Discord bot that answers questions using a FAQ.md file I will provide Analyze existing code git clone https://github.com/google-gemini/gemini-cli cd gemini-cli gemini > Give me a summary of all of the changes that went in yesterday

快速示例:开始一个新项目 cd new-project/ gemini > Write me a Discord bot that answers questions using a FAQ.md file I will provide;分析现有代码 git clone https://github.com/google-gemini/gemini-cli cd gemini-cli gemini > Give me a summary of all of the changes that went in yesterday。

📚 Documentation Getting Started Quickstart Guide - Get up and running quickly. Authentication Setup - Detailed auth configuration. Configuration Guide - Settings and customization. Keyboard Shortcuts - Productivity tips. Core Features Commands Reference - All slash commands (/help, /chat, etc). Custom Commands - Create your own reusable commands. Context Files (GEMINI.md) - Provide persistent context to Gemini CLI. Checkpointing - Save and resume conversations. Token Caching - Optimize token usage. Tools & Extensions Built-in Tools Overview File System Operations Shell Commands Web Fetch & Search MCP Server Integration - Extend with custom tools. Custom Extensions - Build and share your own commands. Advanced Topics Headless Mode (Scripting) - Use Gemini CLI in automated workflows. IDE Integration - VS Code companion. Sandboxing & Security - Safe execution environments. Trusted Folders - Control execution policies by folder. Enterprise Guide - Deploy and manage in a corporate environment. Telemetry & Monitoring - Usage tracking. Tools reference - Built-in tools ov

📚 文档:入门:快速入门指南 - 快速上手;身份验证设置 - 详细的身份验证配置;配置指南 - 设置和自定义;键盘快捷键 - 生产力提示。核心功能:命令参考 - 所有斜杠命令(/help, /chat 等);自定义命令 - 创建您自己的可重用命令;上下文文件 (GEMINI.md) - 为 Gemini CLI 提供持久上下文;检查点 - 保存并恢复对话;Token 缓存 - 优化 Token 使用。工具与扩展:内置工具概述;文件系统操作;Shell 命令;Web 获取与搜索;MCP 服务器集成 - 使用自定义工具进行扩展;自定义扩展 - 构建并共享您自己的命令。高级主题:无头模式(脚本编写) - 在自动化工作流中使用 Gemini CLI;IDE 集成 - VS Code 配套工具;沙盒与安全 - 安全的执行环境;受信任文件夹 - 按文件夹控制执行策略;企业指南 - 在企业环境中部署和管理;遥测与监控 - 使用情况跟踪;工具参考 - 内置工具概述。