详细分析 ▾
运行时依赖
版本
Initial release: Comprehensive guide to Google's Gemini CLI for AI-powered code generation, analysis, and automation from the terminal
安装命令 点击复制
技能文档
A comprehensive guide for using the Gemini CLI tool to build, debug & deploy with AI directly from the command line.
什么 做
Gemini CLI enables command-line access to Google's Gemini models for:
- 查询 Codebases — Analyze 和 understand large codebases
- Generate 从 Images — 创建 code, docs, 或 apps 从 screenshot/images
- Generate 从 PDFs — Extract 和 build 从 PDF documents
- Automate Workflows — Chain AI tasks 对于 complex automation
- Interactive Shell — Chat 带有 Gemini 关于 project
- Debugging — 获取 AI-powered debugging 和 code review
Perfect for developers who want to leverage AI without leaving the terminal.
⚠️ Trust 模型 & Security Declaration
Metadata Declaration:
- 类型: AI CLI tool (Google-managed, official)
- External Binary:
gemini(official Google 包) - Manages Credentials: 否 (credentials stored locally 作为 env var)
- Credential Storage: Environment 变量 (GEMINI_API_KEY)
- Capabilities: Code analysis, generation, automation
- Limitations: Requires internet, API quota limits apply
Authentication 模型:
This tool uses your Gemini API Key passed as an environment variable:
GEMINI_API_KEY= gemini
键 Points:
- ✅ Official Google tool (不 第三个-party)
- ✅ Credentials stored 作为 environment 变量 (不 在...中 tool)
- ✅ 您 control scope: 设置 env var 仅 当...时 needed
- ✅ 否 persistent credential storage 在...中 ~/.gemini/ directory
- ✅ Direct calls 到 Gemini API endpoints (googleapis.com)
什么 Skill 做:
- ✅ Queries codebase 和 documents 带有 Gemini models
- ✅ Generates code/apps 从 images 和 PDFs
- ✅ Runs automated workflows 使用 AI
- ✅ Provides interactive debugging 和 code review
- ❌ 做 不 store credentials
- ❌ 做 不 缓存 sensitive data
- ❌ 做 不 修改 system beyond running commands
Requirements
Binaries (必填):
gemini— Gemini CLI tool (installed 通过 npm)节点— 节点.js 20.0.0+ (usually pre-installed)
Credentials (environment 变量):
GEMINI_API_KEY— Gemini API 键 从 Google AI Studio 或 Google Cloud
System Requirements:
- macOS 15+, Windows 11 24H2+, 或 Ubuntu 20.04+
- 4GB+ RAM (casual usage), 16GB+ (power usage 带有 large codebases)
- Internet 连接 必填
可选:
bash,zsh, 或PowerShell— 任何 modern shell
Installation & Setup
1. Check Installation
Gemini CLI is usually pre-installed:
gemini --version
If not installed:
npm install -g @google/gemini-cli
# OR
brew install gemini-cli
2. 设置 API 键 (One-时间 per 会话)
export GEMINI_API_KEY=""
Or use it inline:
GEMINI_API_KEY="" gemini
To find your API key:
- Go 到 https://aistudio.google.com/app/apikey
- 创建 或 复制 API 键
- Store securely (don't commit 到 git)
3. 验证 Installation
gemini --version
gemini --help
Quick 开始
Interactive Shell (Ask Gemini Questions)
gemini chat
Then type your questions about code, architecture, debugging, etc.
查询 Codebase
gemini code --prompt "What does this function do?"
Generate 从 Image
gemini create --from-image ./screenshot.png --prompt "Create a React component from this design"
Generate 从 PDF
gemini create --from-pdf ./document.pdf --prompt "Create an API spec based on this document"
Automate Workflow
gemini workflow --steps "1) analyze code, 2) identify issues, 3) suggest fixes"
获取 Help
gemini --help
gemini --help
Common Commands
Interactive
gemini chat # Start interactive chat
gemini chat --context ./src # Chat with codebase context
Code Analysis
gemini code --prompt "analyze" ./file.js
gemini code --explain ./function.ts
gemini code --review ./pull_request.patch
Code Generation
gemini create --from-image ./design.png
gemini create --from-pdf ./spec.pdf
gemini create --template react --prompt "counter app"
Batch Operations
gemini batch --input ./tasks.json --output ./results.json
Configuration
- API 键: 设置 通过
GEMINI_API_KEYenvironment 变量 - Temp Storage: Uses system temp directory (auto-cleaned)
- 否 persistent 配置: Unlike mirocli, Gemini CLI doesn't store auth locally
到 persist API 键 穿过 sessions (可选):
Add to your ~/.bashrc, ~/.zshrc, or equivalent:
export GEMINI_API_KEY=""
⚠️ Security warning: Only do this if your shell profile is secure and not synced to public repos.
Global Options
--version # Show version
--help # Show help
--verbose # Verbose output
--api-key # Pass API key directly (overrides env var)
--model # Specify Gemini model (default: gemini-2.5-pro)
Help & Documentation
gemini --help # Global help
gemini --help # Command-specific help
Official Docs: https://geminicli.com/docs
Tips & Tricks
- 使用 带有 codebase:
cd /path/to/your/project
gemini chat --context ./src
- Chain commands:
gemini code --review ./changes.patch | tee review.txt
- Batch process files:
for file in src/*.js; do
gemini code --explain "$file" > "docs/${file}.md"
done
- Store prompts 在...中 files:
cat prompt.txt | gemini chat
当...时 到 使用 Gemini CLI vs 其他 Tools
| Task | Gemini CLI | Cursor/IDE | Web UI |
|---|---|---|---|
| Quick code questions | ✅ Fast | ✅ Integrated | ❌ Context switch |
| Large codebase analysis | ✅ Better | ✅ Native | ❌ Limited |
| Generate from images | ✅ Works | ✅ Works | ✅ Works |
| Batch automation | ✅ Perfect | ❌ Manual | ❌ Manual |
| Interactive chat | ✅ Terminal | ✅ IDE | ✅ Browser |
| Scripting workflows | ✅ Yes | ❌ No | ❌ No |
Status & 下一个 Steps
✅ Installation: Pre-installed (v0.28.2)
✅ Configuration: 就绪 到 使用 带有 GEMINI_API_KEY environment 变量
✅ Authentication: 设置 env var 之前 使用 (否 interactive steps needed)
Testing: Run gemini --help 到 验证 installation
Usage: 设置 API 键 和 开始 使用:
export GEMINI_API_KEY="your-key-here"
gemini chat
Setup 日期: 2026-03-14 Status: 就绪 (否 authentication 必填 — env var based)
免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制