Install and Use Gemini CLI | Generated by AI
Below is a concise guide to installing, setting up, and using the Google Gemini CLI, an open-source AI agent that integrates Gemini’s capabilities into your terminal for coding, task automation, and more. This guide is based on the latest available information as of June 29, 2025.
Google Gemini CLI Guide
What is Gemini CLI?
Gemini CLI is an open-source command-line tool developed by Google that brings the power of the Gemini 2.5 Pro model (with a 1 million token context window) to your terminal. It supports coding, debugging, content generation, task automation, and multimodal tasks like image and video generation. It’s free to use with a Google account and integrates with tools like Google Search and Model Context Protocol (MCP) servers.
Prerequisites
- Node.js: Version 18 or higher. Check with
node -v
. Install from nodejs.org if needed. - Google Account: Required for free access to Gemini 2.5 Pro (60 requests/minute, 1,000 requests/day).
- (Optional) API Key: For higher limits or specific models, generate one from Google AI Studio.
- (Optional) Docker: For MCP server integration (e.g., GitHub tools).
Installation
There are two ways to get started with Gemini CLI:
- Install Globally:
npm install -g @google/gemini-cli gemini
This installs the CLI globally and runs it with the
gemini
command. - Run Without Installing:
npx https://github.com/google-gemini/gemini-cli
This runs the CLI directly without installation, ideal for testing.
Setup
- Launch the CLI:
- Authenticate:
- Choose Login with Google for free access (recommended for most users).
- A browser window will open; sign in with your Google account.
- Alternatively, use an API key:
- Generate a key from Google AI Studio.
- Set it as an environment variable:
export GEMINI_API_KEY=YOUR_API_KEY
- This is useful for higher limits or enterprise use.
- Navigate to Your Project:
Basic Usage
Gemini CLI operates in an interactive Read-Eval-Print Loop (REPL) environment. Type commands or natural language prompts to interact with the Gemini model. Here are some common tasks:
- Code Explanation:
- Code Generation:
- Debugging:
- File Management:
- GitHub Integration:
- Multimodal Tasks:
Key Features
- Context Files (GEMINI.md): Add a
GEMINI.md
file in your project root to define coding styles, project rules, or preferences (e.g., “Use async/await for JavaScript”). The CLI uses this for tailored responses. - Built-in Tools:
- Non-Interactive Mode: For scripting, pipe commands:
echo "Write a Python script" | gemini
- Conversation Memory: Save session history with
/save <tag>
and resume with/restore <tag>
. - Custom Configuration:
Tips and Tricks
- Start with Plans: For complex tasks, ask for a plan first:
Create a detailed implementation plan for a login system
. This ensures structured output. - Use Local Context: Encode project-specific details in
GEMINI.md
instead of relying on MCP servers for faster, reliable responses. - Debugging: Enable verbose logging with
DEBUG=true gemini
for detailed request/response info. - Review Changes: Always review file modifications or commands before approving (type
y
to confirm). - Explore Tools: Run
/tools
to discover built-in capabilities like web search or memory saving.
Troubleshooting
- Authentication Issues: Ensure your Google account or API key is valid. Use
/auth
to switch methods. - Rate Limits: The free tier allows 60 requests/minute and 1,000/day. For higher limits, use an API key or Vertex AI.
- Errors: Check the Troubleshooting Guide on GitHub.
- Slow Responses: The CLI is in preview and may be slow with API calls. File feedback on GitHub.
Advanced Usage
- MCP Server Integration:
- Scripting: Automate tasks by integrating Gemini CLI into scripts:
gemini --non-interactive "Generate a bash script to backup my files"
- Multimodal Prompts:
Limitations
- Preview Stage: Gemini CLI is in pre-GA, with potential for limited support or bugs.
- Not Fully Open-Source: Only the CLI UI is Apache 2.0 licensed; the Gemini model is proprietary.
- Quota Sharing: Limits are shared with Gemini Code Assist if used.
- Future Pricing: Post-preview pricing is unclear; advanced features may require payment.
Resources
- Official GitHub: github.com/google-gemini/gemini-cli
- Documentation: gemini-cli.click or GitHub docs
- Blog Announcement: blog.google
- Feedback: File bugs or suggestions on GitHub.
Example Workflow
- Install:
npm install -g @google/gemini-cli
- Run:
cd my-project && gemini
- Authenticate: Log in with Google.
- Prompt:
Write a Python script for a REST API with FastAPI
. - Review and save the generated code.
- Use
/tools
to explore additional features like GitHub integration.
Gemini CLI is a powerful tool for developers, offering seamless AI integration in the terminal. Start simple, leverage GEMINI.md
for context, and explore its multimodal capabilities to boost productivity. For more examples, check the GitHub tutorials.
If you need specific examples or have questions about a particular feature, let me know!