This guide will walk you through setting up the Gemini CLI on a Linux system. The Gemini CLI is a powerful tool for interacting with Google’s Gemini models directly from your command line, enabling scripting, automation, and quick experimentation with AI models.
Download the binary: Download the appropriate binary for your Linux distribution from the official Gemini releases page.
Make it executable:
chmod +x gemini-cli-linux
Move and rename the binary to a directory in your PATH:
sudo mv gemini-cli-linux /usr/local/bin/gemini
Get your API key: Obtain your API key from Google AI Studio.
Set the API key as an environment variable:
export GEMINI_API_KEY="YOUR_API_KEY"
You can add this line to your ~/.bashrc or ~/.zshrc file to make it permanent. Important: Keep your API key secure and never commit it to version control.
Check the version:
gemini --version
Run a prompt:
gemini "Hello, world!"
Use with pipes:
cat my_code.py | gemini "Explain this code"
You have successfully set up the Gemini CLI on your Linux system. This powerful tool allows for seamless interaction with Google’s Gemini models directly from your terminal, opening up possibilities for scripting, automation, and rapid prototyping. Explore the official Gemini CLI documentation for more advanced features and usage examples.