Run Your First Command

Verify your Gemini CLI setup by running your first command and getting familiar with basic usage.

Pre-flight Check

Before running your first command, ensure you have:

  • Gemini CLI installed
  • Google AI API key configured
  • Internet connection active

Your First Command

Let's start with a simple test:

gemini "Hello, world! Can you help me with coding?"

This command sends a simple prompt to verify your setup is working.

Common Commands

Check Version

gemini --version

Get Help

gemini --help

Explain Code

gemini "Explain this code" < script.js

Practical Command Examples

Now that you have verified your setup, here are five real-world examples that demonstrate the power of Gemini CLI in everyday development workflows. Each example shows a different use case so you can start being productive right away.

1. Generate Code

gemini "Write a Python function that validates email addresses"

Gemini CLI will respond with a complete, well-structured Python function including docstrings and example usage. The generated code typically includes input validation, regex patterns, and edge case handling. You can copy the output directly into your project or pipe it to a file.

2. Explain Existing Code

cat app.py | gemini "Explain this code line by line"

By piping a file into Gemini CLI, you can get a detailed line-by-line explanation of any codebase. This is particularly useful when onboarding to a new project or reviewing unfamiliar code. Gemini will break down each section, explain the logic, and highlight any potential issues or improvements.

3. Debug Errors

gemini "Why am I getting 'ModuleNotFoundError: No module named requests' in Python?"

Paste any error message directly into your prompt and Gemini will diagnose the root cause. For this example, it will explain that the requests library is not installed in your current environment and provide the exact pip install command to fix it, along with tips for managing virtual environments.

4. Write Documentation

gemini "Write a README.md for a Node.js REST API project"

Gemini CLI can generate professional documentation in markdown format, including sections for installation, configuration, API endpoints, and contributing guidelines. The output is ready to use as a starting point and can be customized to match your specific project details.

5. Refactor Code

gemini "Refactor this function to use async/await" < legacy.js

Using file input redirection with the < operator, you can feed an entire file to Gemini CLI along with refactoring instructions. Gemini will return the modernized version of your code with proper async/await patterns, error handling, and explanations of what changed and why.

Understanding Gemini CLI Output

Knowing how Gemini CLI formats and delivers its responses will help you work with it more effectively. Here is what to expect when you run commands.

Markdown-Formatted Responses

Gemini CLI renders its output using markdown formatting directly in your terminal. This means you will see properly formatted headings, bold text, code blocks with syntax highlighting, bullet lists, and numbered steps. Code snippets are wrapped in fenced code blocks with language identifiers, making them easy to distinguish from explanatory text.

Streaming vs Complete Responses

By default, Gemini CLI streams responses token by token as they are generated, so you can start reading the output immediately without waiting for the full response to complete. This is especially useful for longer responses like code generation or detailed explanations. For shorter prompts, the response may appear to arrive all at once due to the speed of generation.

Save Output to a File

You can redirect Gemini CLI output directly to a file using standard shell redirection. This is useful for saving generated code, documentation, or analysis results for later use.

gemini "your prompt" > output.md

Select a Specific Model

Use the -m flag to choose a specific Gemini model for your request. Different models offer different trade-offs between speed, capability, and cost. For example, you might use a smaller model for quick questions and a larger model for complex code generation tasks.

gemini -m gemini-2.5-pro "Optimize this database query"

Common Errors When Getting Started

If something goes wrong on your first attempt, do not worry. Here are the most common errors new users encounter and how to resolve each one quickly.

API Key Not Configured

Error: API key not configured

This error means Gemini CLI cannot find a valid Google AI API key. You need to set up your API key before using any commands. Follow our step-by-step API key configuration guide to resolve this issue. Make sure the key is exported as an environment variable or saved in your configuration file.

Network Timeout

Error: Network timeout

A network timeout indicates that Gemini CLI could not reach the Google AI API servers. Check that your internet connection is active and stable. If you are behind a corporate firewall or VPN, ensure that outbound HTTPS connections to Google API endpoints are allowed. You can test connectivity by running curl https://generativelanguage.googleapis.com in your terminal.

Rate Limit Exceeded

Error: Rate limit exceeded

This error occurs when you have sent too many requests in a short period. The free tier of Google AI API has usage limits per minute and per day. Wait a few minutes before trying again, or consider upgrading your API plan. Learn more about Gemini CLI rate limits and how to manage them.

Command Not Found: gemini

bash: gemini: command not found

This means Gemini CLI is not installed or not in your system PATH. If you have not installed it yet, visit our npm installation guide or Homebrew installation guide to get started. If you installed it recently, try opening a new terminal window or running source ~/.bashrc to refresh your PATH.

Related Questions

Next Steps

Great! Now explore more advanced features: