Gemini CLI Configuration Guide
Gemini CLI Configuration Guide
Section titled “Gemini CLI Configuration Guide”Gemini CLI is Google’s official command-line tool, designed to give developers a powerful AI-assisted coding experience. It supports intelligent code generation, code analysis, debugging assistance, and more.
:rocket: Key Features
Section titled “:rocket: Key Features”- Intelligent code generation - Quickly generate high-quality code
- Code analysis - Deeply understand and analyze code structure
- Debugging assistant - Smartly detect and fix code issues
- Documentation generation - Automatically generate code documentation
- Command-line integration - Seamlessly integrate into your development workflow
:star: Which models can be used with Gemini CLI
Section titled “:star: Which models can be used with Gemini CLI”All Gemini models on this site are supported in Gemini CLI
:package: Installation Steps
Section titled “:package: Installation Steps”1. Install Gemini CLI
Section titled “1. Install Gemini CLI”npm install -g @google/gemini-cli # macOS/Linux需sudo权限2. Mac & Liunx configuration
Section titled “2. Mac & Liunx configuration”Terminal setup method
Section titled “Terminal setup method”Run the following commands in Terminal:
export GOOGLE_GEMINI_BASE_URL="https://api.4allapi.com"export GEMINI_API_KEY="你的API密钥"export GEMINI_MODEL="gemini-3-pro"Permanent setup method
Section titled “Permanent setup method”Add the following to your shell configuration file:
For zsh (default)
Section titled “For zsh (default)”echo 'export GOOGLE_GEMINI_BASE_URL="https://api.4allapi.com"' >> ~/.zshrcecho 'export GEMINI_API_KEY="你的API密钥"' >> ~/.zshrcecho 'export GEMINI_MODEL="gemini-2.5-pro"' >> ~/.zshrcsource ~/.zshrcFor bash
Section titled “For bash”echo 'export GOOGLE_GEMINI_BASE_URL="https://api.4allapi.com"' >> ~/.bash_profileecho 'export GEMINI_API_KEY="你的API密钥"' >> ~/.bash_profileecho 'export GEMINI_MODEL="gemini-2.5-pro"' >> ~/.bash_profilesource ~/.bash_profileVerify Gemini CLI environment variables
Section titled “Verify Gemini CLI environment variables”Verify in Terminal:
echo $GOOGLE_GEMINI_BASE_URLecho $GEMINI_API_KEYecho $GEMINI_MODEL3. Windows configuration
Section titled “3. Windows configuration”PowerShell setup method
Section titled “PowerShell setup method”Run the following commands in PowerShell:
$env:GOOGLE_GEMINI_BASE_URL = "https://api.4allapi.com"$env:GEMINI_API_KEY = "你的API密钥"$env:GEMINI_MODEL = "gemini-3-pro"Permanent PowerShell setup (user-level)
Section titled “Permanent PowerShell setup (user-level)”Run the following commands in PowerShell:
# Set user-level environment variables (persistent)[System.Environment]::SetEnvironmentVariable("GOOGLE_GEMINI_BASE_URL", "https://api.4allapi.com", [System.EnvironmentVariableTarget]::User)[System.Environment]::SetEnvironmentVariable("GEMINI_API_KEY", "你的API密钥", [System.EnvironmentVariableTarget]::User)[System.Environment]::SetEnvironmentVariable("GEMINI_MODEL", "gemini-2.5-pro", [System.EnvironmentVariableTarget]::User):bulb: After making these changes, you need to reopen the PowerShell window for them to take effect.
Verify Gemini CLI environment variables
Section titled “Verify Gemini CLI environment variables”Verify in PowerShell:
echo $env:GOOGLE_GEMINI_BASE_URLecho $env:GEMINI_API_KEYecho $env:GEMINI_MODELCore Command Reference
Section titled “Core Command Reference”Basic interaction
Section titled “Basic interaction”gemini # Enter interactive modegemini -p "解释这段代码" @./src/utils.js # File analysisgemini --media wireframe.png "转换为React组件" # Multimodal processingSession management
Section titled “Session management”# View command help/quit # Exit and show session statistics/chat save feature_dev # Save current session/chat resume feature_dev # Resume sessionTool integration
Section titled “Tool integration”!ls -la # Run a system command/tools # Show available toolsgemini review --staged-files --format=checklist # Git integrationRepository operations
Section titled “Repository operations”gemini -p "@./ 总结项目架构" # Analyze the entire directorygemini -p "@src/components/Button.jsx 生成单元测试" # Specific filegemini "迁移Django项目到Python3.12" # Break down complex tasksAdvanced Memory Management (/memory Command)
Section titled “Advanced Memory Management (/memory Command)”Command comparison
Section titled “Command comparison”| Command | Function | Use case |
|---|---|---|
| /memory add | Add a new instruction | gemini /memory add “Always reply in Chinese” |
| /memory show | Show current memory | Verify AI context |
| /memory refresh | Reload the configuration file | After updating GEMINI.md |
Configuration file practice
Section titled “Configuration file practice”1. Create GEMINI.md to define project rules:
Section titled “1. Create GEMINI.md to define project rules:”# 项目规范- 使用TypeScript严格模式- 函数命名:camelCase- API响应格式:{ data, error }2. Refresh the configuration:
Section titled “2. Refresh the configuration:”/memory refresh # Reload all configuration/memory show # Verify loaded contentSupports automatic scanning of multi-level directories; enterprise projects can define unified team standards
State Recovery (/restore Command)
Section titled “State Recovery (/restore Command)”Workflow
Section titled “Workflow”# Enable checkpointing at startupgemini --checkpointing
# After performing operations that may modify files/restore # View recoverable checkpoints
# Restore to a specific state/restore checkpoint_42Applicable scenarios:
Section titled “Applicable scenarios:”- Roll back after a failed code-generation experiment
- Recover from file editing mistakes
- Create safety snapshots before batch operations
Error Handling Guide
Section titled “Error Handling Guide”Common error solutions
Section titled “Common error solutions”| Error type | Symptom | Solution |
|---|---|---|
| Authentication failure | API key not found | Check environment variables or reset config.json |
| Quota exceeded | 429 Too Many Requests | Switch to another model or wait |
| Context overflow | No clear error code (performance degradation) | Reduce input size / process in chunks |
| File creation failed | Insufficient permissions | Run with administrator privileges or check directory permissions |
| Network error | Connection timed out | 1. Verify the proxy 2. Use curl to test API reachability |
Debugging tools
Section titled “Debugging tools”gemini -d # Enable verbose debug mode/stats # View resource usage4All API Footer
Section titled “4All API Footer”4All API · One-stop AI large model API aggregation platform | Pricing | Contact us
© 2025 4All API. All rights reserved.