How to Install Gemini CLI on Linux
A comprehensive step-by-step setup and deployment guide
Table of Contents
- Step 1: Install Prerequisites (Node.js)
- Step 2: Install Gemini CLI
- Step 3: Launch and Authenticate
- Quick Usage Examples
Installing the official Google Gemini CLI (an open-source AI agent for your terminal) on Linux is quick and straightforward. Because it is a Node.js-based application, you just need a compatible Node environment configured on your system.
Step 1: Install Prerequisites (Node.js)
The Gemini CLI requires Node.js version 20.0.0 or higher.
If you are using a Debian/Ubuntu-based system, the default package manager versions might be outdated. Using NVM (Node Version Manager) or the NodeSource repository is highly recommended.
Option A: Using NVM (Recommended)
-
Run the NVM installer:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash -
Restart your terminal or source your profile configuration:
source ~/.bashrc(Or use
source ~/.zshrcdepending on your active shell) -
Install and switch to Node 20+:
nvm install 20 nvm use 20
Option B: Using Ubuntu/Debian Package Manager
Alternatively, you can pull the LTS binaries directly from NodeSource:
sudo apt update && sudo apt install -y curl
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
Step 2: Install Gemini CLI
Once Node.js and npm are properly configured, you can install the CLI package globally on your system.
sudo npm install -g @google/gemini-cli
Alternative (No-Install Method): If you just want to evaluate or try out the CLI tool without permanently installing it to your system paths, you can leverage
npxto execute it instantly on demand:npx @google/gemini-cli
Step 3: Launch and Authenticate
To initialize the setup and start the CLI runtime environment, simply execute:
gemini
Authentication Options
Upon your very first launch sequence, the CLI tool will prompt you to choose an interface theme and complete your authentication. You have two main pathways:
- Option 1: Sign in with Google (OAuth) [Highly Recommended] — Selecting this opens a standard browser session to authenticate securely via your personal Google account. This structural tier grants a generous free allocation (typically allowing up to 1,000 requests per day) without requiring active token management.
- Option 2: Gemini API Key — If you prefer a headless interface or standard backend token architecture, fetch an API key from Google AI Studio and export it directly to your target shell pipeline environment:
export GEMINI_API_KEY="your_actual_api_key_here"
Quick Usage Examples
Once completely configured, you can query and leverage the AI agent directly inside your pipeline infrastructure:
-
Interactive Mode: Launch the persistent chat session:
gemini -
Single Prompt (Non-Interactive): Run queries directly and capture stdout:
gemini "Explain how to optimize this bash script" -
Specify a Specific Model: Override default operational models:
gemini -m gemini-2.5-flash -
Include Local File Context & Directories: Feed structural directory code context explicitly to the agent:
gemini --include-directories ./src,./docs
Google Gemini CLI Documentation | 2026