The ultimate beginner's guide to installing gemini-cli, including battle-tested solutions for common network proxy and authentication issues you won't find in the official docs
2025-07-04 • 5 min readSo, you've heard about gemini-cli
, the powerful command-line tool that brings Google's AI models directly to your terminal. You're excited, but maybe also a little wary. You've been down this road before: cryptic installation errors, confusing authentication steps, and that sinking feeling that you're missing a critical piece of the puzzle.
You're right to be cautious. For many developers, the journey stops before it even begins, blocked by obscure network proxy issues or confusing GOOGLE_CLOUD_PROJECT
requirements.
This article is designed to change that narrative. It's more than just a quickstart; it's a battle-tested walkthrough that anticipates and solves the most common frustrations.
Now, let me help you get started quickly. The following is a complete, unabridged chapter excerpted from my comprehensive guide, Gemini CLI: From Zero to Automated Workflows.
The goal of this chapter is singular: to guide you flawlessly from zero to one. We will navigate the installation, solve common configuration issues preemptively, and get your first command running successfully in the shortest time possible.
Before we begin, ensure you have Node.js installed on your system, and its version is 18 or higher. You can check your current version by running node -v
in your terminal.
gemini-cli
offers two primary installation methods. Choose the one that best fits your needs.
Method A: Global Install (Recommended)
npm install -g @google/gemini-cli
gemini-cli
once on your system, allowing you to run the gemini
command from any directory. It's the most convenient option for long-term use.Method B: NPX Execution (For a Quick Test)
npx @google/gemini-cli
gemini-cli
without permanently installing it on your system. It's perfect for a quick trial or one-off tasks.Many corporate or development environments require a network proxy. Attempting to authenticate through a proxy without proper configuration will almost certainly fail. This is the first major hurdle this guide will help you overcome.
The Root Cause: The "Login with Google" authentication process requires your browser to redirect back to a localhost
address on your machine after a successful login. If you've configured a system-wide proxy but haven't excluded localhost
, this critical callback request is mistakenly sent to the external proxy server, which doesn't know how to route it back to your machine. This causes the authentication to hang or fail.
Windows Solution (Batch Scripts): We recommend using batch scripts to easily toggle your proxy settings.
set_proxy.bat
(Run when on the proxy network):
Save the following as a .bat
file. Run it as an administrator before you need to use gemini-cli
.
:: Set your proxy. Replace 7897 with your actual proxy port.
setx HTTP_PROXY "http://localhost:7897"
setx HTTPS_PROXY "http://localhost:7897"
:: CRITICAL STEP: Exclude localhost to allow the auth callback to succeed.
setx NO_PROXY "localhost,127.0.0.1"
echo Proxy environment for gemini-cli set successfully.
unset_proxy.bat
(Run when off the proxy network):
Create this file to quickly clear the proxy settings.
setx HTTP_PROXY ""
setx HTTPS_PROXY ""
setx NO_PROXY ""
echo Proxy environment cleared.
gemini-cli
cleverly manages configuration at two levels, allowing for both general defaults and project-specific overrides.
Global (User-level) Configuration (Recommended for primary credentials):
This is the ideal place for settings you use everywhere, like your primary API key. The configuration is stored in ~/.gemini/
.
Project-level Configuration:
For settings specific to one project (like a unique GOOGLE_CLOUD_PROJECT
), you can create a .gemini
folder inside that project's directory. These settings will override any global settings, but only when you run gemini
from within that project folder.
.gemini
Directory: Using .env
and settings.json
Based on the hierarchy above, we recommend the following best practice for managing your configurations.
Use .env
for Credentials:
To securely and flexibly manage your credentials, use a .env
file. gemini-cli
will automatically load variables from a file named .env
inside the .gemini
directory. Create your primary .env
file in your global user directory (~/.gemini/.env
).
# Example for ~/.gemini/.env
# If you use API Key auth, add your primary key here.
GEMINI_API_KEY="YOUR_PRIMARY_API_KEY_HERE"
For a project that needs a specific Google Cloud Project, create a separate .gemini/.env
file inside that project's folder with just that variable: GOOGLE_CLOUD_PROJECT="YOUR_PROJECT_ID_HERE"
.
A Glimpse into settings.json
:
Alongside .env
, the .gemini
directory is also home to settings.json
. This file is used for persistent, non-secret configurations, such as changing the CLI's theme or enabling advanced features like sandboxing. We will explore this file in detail in later chapters, but it's important to know it exists as part of the core configuration system.
You are now ready to run the gemini
command for the first time, which will initiate the authentication process.
Option 1: Login with Google (The Generous Free Quota Path)
Process: A browser window will open to guide you through the Google login process.
IMPORTANT: The Mandatory GOOGLE_CLOUD_PROJECT
Configuration
For many users, simply logging in is not enough. The authentication will fail unless you pre-configure a GOOGLE_CLOUD_PROJECT
environment variable. This is not an optional step if you fall into any of the following categories:
If you meet any of these conditions, follow the next two sections precisely.
Step-by-Step: Enabling the API and Finding Your Project ID
Before you can configure the variable, you must enable the correct API in your Google Cloud project and get your Project ID.
Navigate to the Gemini API Page: Open your browser and go to the official Gemini for Google Cloud API page in the marketplace:
Select Your Project: At the top of the Google Cloud console, ensure you have selected the correct project from the dropdown menu. If you don't have one, you'll need to create one first.
Enable the API: You will see a blue button.
Copy Your Project ID: Once the API is enabled, locate and copy your Project ID. You can find it in the "Project info" card on your project's main dashboard, or by clicking the project selection dropdown at the top of the page. The ID is a unique string, often in the format your-project-name-123456
.
Final Step: Configure the Environment Variable
With your Project ID copied, you must now provide it to gemini-cli
. As established in Section 1.5, the best method is to create a project-specific .env
file.
In your project's root directory, create the following file path: .gemini/.env
.
Open the .env
file and add the following line, replacing "your-copied-project-id"
with the ID you just copied from the Google Cloud console.
# Inside your-project/.gemini/.env
GOOGLE_CLOUD_PROJECT="your-copied-project-id"
Now, when you run gemini
from within this project folder, it will automatically load this variable, and your "Login with Google" authentication will succeed.
Option 2: Gemini API Key (The Automation-Ready Path)
.gemini/.env
file.Problem: gemini: command not found
?
gemini-cli
is not in your system's PATH
environment variable.(Get-Command gemini).Source
in PowerShell or where gemini
in CMD to find the absolute path, then add this path to your system's environment variables.which gemini
to find the path and ensure it's in your PATH
.Problem: Authentication fails with TLS connection failed
or other network errors?
npm uninstall -g @google/gemini-cli
.npm config get cache
, then delete the _npx
folder within that directory.Congratulations! You have successfully installed, configured, and authenticated gemini-cli
, sidestepping the most common and frustrating issues that block new users. You now have a working tool, but you've only scratched the surface of its true potential.
What's next?
How do you use the @
command to make the AI understand your entire codebase? How do you craft a GEMINI.md
file to teach it your project's specific coding standards? How do you set up an MCP server to connect it to external APIs and build truly powerful, automated workflows?
This setup guide is just the first step.
If you found this detailed chapter helpful, it's just a glimpse of the value packed into the complete, unofficial handbook: Gemini CLI: From Zero to Automated Workflows.
In the full guide, you will get exclusive access to:
GEMINI.md
strategies to craft a bespoke AI "brain" for your projects.Stop wasting hours on trial-and-error. Get the complete guide now and become a gemini-cli
master today.
Master the Command-Line. Automate Your Workflow.