Gemini CLI Quickstart
This guide provides detailed instructions on how to install and configure the Gemini Command Line Interface (CLI) on your computer, with a special focus on requirements for scientific network environments. Gemini CLI allows you to interact with the Gemini API via the terminal, offering greater flexibility in developing and testing your applications.
1. Install Gemini CLI
We will use Homebrew to install Gemini CLI. Homebrew is a package manager for macOS and Linux that simplifies software installation.
1.1 Prerequisites
Before installing Gemini CLI, make sure your system has Homebrew installed. If not, install it using the command below:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
1.2 Install the CLI
Once Homebrew is ready, open your terminal and run:
brew install gemini-cli
After installation, you can launch Gemini CLI anywhere with:
gemini
2. Obtain and Configure Your Gemini API Key
A Gemini API key is essential for accessing Gemini models and features. Google AI Studio offers a free tier that allows up to 100 daily uses of the Gemini 2.5 Pro model, with the option to control which model you use. Paid plans offer higher rate limits.
2.1 Generate an API Key
Visit Google AI Studio
and log in with your Google account. In the console, click the Generate Key
button.If you see the message Unable to create API key, you’ll need to manually create one in Google Cloud Console
, then return to Google AI Studio and select your existing project (e.g., “gemini cli (xxxx-123456-xx)”).
When successful, you’ll see the message “API key generated.” Important: Store your API key securely. Never share it or embed it in publicly accessible code to prevent unauthorized use.
2.2 Set the Environment Variable
To let Gemini CLI use your API key, set it as an environment variable. Open your terminal config file (commonly ~/.zprofile
on macOS):
open ~/.zprofile
Add the following line at the end, replacing YOUR_API_KEY
with the actual key:
export GEMINI_API_KEY="YOUR_API_KEY"
Save and close the file. Simply restart the terminal session.
3. Notes for Scientific Network Environments
In scientific or restricted network settings, accessing Google services may be difficult. If you encounter issues like slow downloads via Homebrew or failed API key creation, consider the following:
- Configure a proxy server
- Adjust firewall rules
- Use VPN/accelerator