Gemini

CLI Reference

Reference guide for the Gemini Command Line Interface - generate code, text, and images generation directly from the terminal.

Start Using CLI

Getting Started

📥

Install CLI

Install the Gemini cli using your package manager or download standalone binaries. Supports Windows, macOS, and Linux distributions.

{`# Linux/macOS
curl -fsSL https://cli.gemini.com/install.sh | sh
source ~/.bashrc`}  
            
{`# Windows (PowerShell)
iwr https://cli.gemini.com/win.zip -O gemini.zip
Expand-Archive gemini.zip -DestinationPath .`}  
            
{`# Docker
docker run -it --volume .:/app gemini`}  
            
🔗 Download for All Platforms

Authentication

🔐

Secure Your CLI

{`# After visiting developer console and getting an API key:
gemini config set api_key "your_api_key_here"
# or set environment variable
export GEMINI_API_key="your_api_key"`
          

The CLI will automatically use the API key from either environment variables or the config file.

CLI Commands

🧠

Code Generation

{`$ gemini code "Create a Python function to reverse a string"

Output saved to: /output/reverse_string.py
# Generated content:
def reverse_string(s):
    return s[::-1]`}  
            

Generate production-ready code from natural language prompts with optional syntax highlighting and formatting.

Flags: --language, --framework Output: Files, clipboard, or stdout
✍️

Text Generation

{`$ gemini write "Explain quantum computing to a child"

Saved to: blog/post.md
# Generated content:
Imagine quantum computing is like a magic box that can solve puzzles...`}  
            

Generate blog posts, explanations, documentation, or any text content in 100+ languages.

Flags: --language, --format Output: File, clipboard, or markdown
🎨

Image Generation

{`$ gemini image "Cyberpunk city neon lights, 8K resolution"

Saved to: images/cyberpunk.jpg
# Image with ID: ai_image_783921`}
            

Create images based on text descriptions with options for resolution, style, and media format.

Flags: --aspect-ratio, --style Output: Image files or URL

Advanced Usage

🔄

Pipeline Processing

{`gemini code "Web app with CRUD" |
gemini doc |
gemini test`}  
            

Combine commands in a pipeline to create code, documentation, and tests in one workflow.

Interactive Mode

{`$ gemini chat
> Create a logo design for a tech startup
> Add dark mode to the website
> Explain the business model`}
            

Use the interactive chat mode for multi-turn conversations with your project.

Command Options

Common CLI Options

Option Description
-c, --config <PATH> Custom config file path
-v, --version Display CLI version (1.4.3)
-h, --help Show command help

Output Formats

📄
text
🐍
code
🖼️
image
📘
markdown

Usage Examples

Create an API server

{`$ gemini code "fastapi CRUD app with JWT auth" File created: main.py File created: requirements.txt $ pip install -r requirements.txt $ uvicorn main:app --reload`}

Design an infographic

{`$ gemini image "Infographic: Climate Change Facts" --style modern Image with ID: infographic_23150 Open in viewer: https://view.gemini.com/infographic_23150`}

Research paper summary

{`$ gemini write "Summarize this research paper" < paper.pdf > summary.md Summary saved to: summary.md File size: 1.2 MB`}

Debug error

{`$ cat error.log | gemini debug Proposeded fix saved to: fix.patch Apply with: patch -p0 < fix.patch`}

Configuration

Configuration File

The cli uses a $HOME/.gemini/config.yml file by default. Here are some common entries:

{`api_key: your_key_here default_language: python output_dir: ~/projects cache: true verbose: false`}
Show configuration
$ gemini config
Edit configuration
$ gemini config edit
Export as ENV
$ gemini config env > env_vars.sh

Start Mastering Gemini CLI

Execute complex tasks from your terminal with natural language commands. Create, analyze, and innovate at the speed of thought.

Try CLI Commands