Install and Use Gemini CLI | Generated by AI

Home PDF

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


Installation

There are two ways to get started with Gemini CLI:

  1. Install Globally:
    npm install -g @google/gemini-cli
    gemini
    

    This installs the CLI globally and runs it with the gemini command.

  2. Run Without Installing:
    npx https://github.com/google-gemini/gemini-cli
    

    This runs the CLI directly without installation, ideal for testing.


Setup

  1. Launch the CLI:
    • Run gemini in your terminal.
    • On first run, select a theme (e.g., ASCII, dark, light) and press Enter.
  2. 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.
  3. Navigate to Your Project:
    • Run gemini in your project’s root directory to provide context for code-related tasks.

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:

  1. Code Explanation:
    • Navigate to a project folder and run:
      gemini
      
    • Prompt: Explain the architecture of this project or Describe the main function in main.py.
    • The CLI reads files and provides a structured explanation.
  2. Code Generation:
    • Prompt: Create a simple to-do app in HTML, CSS, and JavaScript.
    • The CLI generates the code and can save it to files if requested.
  3. Debugging:
    • Paste an error message or stack trace and ask: What’s causing this error?.
    • The CLI analyzes the error and suggests fixes, potentially using Google Search for additional context.
  4. File Management:
    • Prompt: Organize my PDF invoices by month of expenditure.
    • The CLI can manipulate files or convert formats (e.g., images to PNG).
  5. GitHub Integration:
    • Use MCP servers for GitHub tasks (e.g., listing issues):
      • Configure a GitHub MCP server in .gemini/settings.json with a Personal Access Token (PAT).
      • Prompt: Get all open issues assigned to me in the foo/bar repo.
    • Run /mcp to list configured MCP servers and tools.
  6. Multimodal Tasks:
    • Generate media with tools like Imagen or Veo:
      • Prompt: Create a short video of a cat’s adventures in Australia using Veo.

Key Features


Tips and Tricks


Troubleshooting


Advanced Usage


Limitations


Resources


Example Workflow

  1. Install: npm install -g @google/gemini-cli
  2. Run: cd my-project && gemini
  3. Authenticate: Log in with Google.
  4. Prompt: Write a Python script for a REST API with FastAPI.
  5. Review and save the generated code.
  6. 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!


Back 2025.06.29 Donate