To use Gemini CLI, you’ll need to authenticate with Google. This guide helps you
quickly find the best way to sign in based on your account type and how you’re
using the CLI.
For most users, we recommend starting Gemini CLI and logging in with your
personal Google account.
Organization accounts: Accounts using paid licenses through an
organization such as a company, school, or
Google Workspace. Includes
Google AI Ultra for Business
subscriptions.
If you run Gemini CLI on your local machine, the simplest authentication method
is logging in with your Google account. This method requires a web browser on a
machine that can communicate with the terminal running Gemini CLI (e.g., your
local machine).
Important: If you are a Google AI Pro or Google AI Ultra
subscriber, use the Google account associated with your subscription.
To authenticate and use Gemini CLI:
Start the CLI:
Terminal window
gemini
Select Login with Google. Gemini CLI opens a login prompt using your web
browser. Follow the on-screen instructions. Your credentials will be cached
locally for future sessions.
Most individual Google accounts (free and paid) don’t require a Google Cloud
project for authentication. However, you’ll need to set a Google Cloud project
when you meet at least one of the following conditions:
You are using a company, school, or Google Workspace account.
You are using a Gemini Code Assist license from the Google Developer Program.
You are using a license from a Gemini Code Assist subscription.
Warning: Treat API keys, especially for services like Gemini, as sensitive
credentials. Protect them to prevent unauthorized access and potential misuse
of the service under your account.
To use Gemini CLI with Google Cloud’s Vertex AI platform, choose from the
following authentication options:
A. Application Default Credentials (ADC) using gcloud.
B. Service account JSON key.
C. Google Cloud API key.
Regardless of your authentication method for Vertex AI, you’ll need to set
GOOGLE_CLOUD_PROJECT to your Google Cloud project ID with the Vertex AI API
enabled, and GOOGLE_CLOUD_LOCATION to the location of your Vertex AI resources
or the location where you want to run your jobs.
For example:
Terminal window
# Replace with your project ID and desired location (e.g., us-central1)
Consider this method of authentication in non-interactive environments, CI/CD
pipelines, or if your organization restricts user-based ADC or API key creation.
Note: If you have previously set GOOGLE_API_KEY or GEMINI_API_KEY, you
must unset them:
# Replace YOUR_GOOGLE_API_KEY with your Vertex AI API key
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
Note: If you see errors like
"API keys are not supported by this API...", your organization might
restrict API key usage for this service. Try the other Vertex AI
authentication methods instead.
Important: Most individual Google accounts (free and paid) don’t require a
Google Cloud project for authentication.
When you sign in using your Google account, you may need to configure a Google
Cloud project for Gemini CLI to use. This applies when you meet at least one of
the following conditions:
You are using a Company, School, or Google Workspace account.
You are using a Gemini Code Assist license from the Google Developer Program.
You are using a license from a Gemini Code Assist subscription.
To configure Gemini CLI to use a Google Cloud project, do the following:
Configure your environment variables. Set either the GOOGLE_CLOUD_PROJECT
or GOOGLE_CLOUD_PROJECT_ID variable to the project ID to use with Gemini
CLI. Gemini CLI checks for GOOGLE_CLOUD_PROJECT first, then falls back to
GOOGLE_CLOUD_PROJECT_ID.
For example, to set the GOOGLE_CLOUD_PROJECT_ID variable:
Terminal window
# Replace YOUR_PROJECT_ID with your actual Google Cloud project ID
To avoid setting environment variables for every terminal session, you can
persist them with the following methods:
Add your environment variables to your shell configuration file: Append
the export ... commands to your shell’s startup file (e.g., ~/.bashrc,
~/.zshrc, or ~/.profile) and reload your shell (e.g.,
source ~/.bashrc).
Warning: Be aware that when you export API keys or service account
paths in your shell configuration file, any process launched from that
shell can read them.
Use a .env file: Create a .gemini/.env file in your project
directory or home directory. Gemini CLI automatically loads variables from
the first .env file it finds, searching up from the current directory,
then in ~/.gemini/.env or ~/.env. .gemini/.env is recommended.
Example for user-wide settings:
Terminal window
mkdir-p~/.gemini
cat>>~/.gemini/.env<<'EOF'
GOOGLE_CLOUD_PROJECT="your-project-id"
# Add other variables like GEMINI_API_KEY as needed
EOF
Variables are loaded from the first file found, not merged.
When running Gemini CLI within certain Google Cloud environments, authentication
is automatic.
In a Google Cloud Shell environment, Gemini CLI typically authenticates
automatically using your Cloud Shell credentials. In Compute Engine
environments, Gemini CLI automatically uses Application Default Credentials
(ADC) from the environment’s metadata server.
If automatic authentication fails, use one of the interactive methods described
on this page.