🚀 What is Gemini CLI?
Gemini CLI is a command-line interface tool developed by Google that integrates Gemini 2.5 Pro AI capabilities into your terminal. It allows developers to interact with AI models for tasks like code generation, debugging, and content creation without leaving the command line.
🛠️ Prerequisites
Before installing Gemini CLI, ensure you have:
-
Node.js version 18 or higher
-
npm (Node Package Manager)
You can verify your Node.js installation by running:
node -v
If Node.js is not installed, download it from the official website and follow the installation instructions.
📥 Installation
You have two options to install Gemini CLI:
Option 1: Global Installation
Install Gemini CLI globally using npm:
npm install -g @google/gemini-cli
After installation, you can start Gemini CLI by typing:
gemini
Option 2: Run with npx
If you prefer not to install it globally, you can run Gemini CLI using npx:
npx @google/gemini-cli
This method runs the CLI without adding it to your global packages.()
🔐 Authentication
Upon launching Gemini CLI for the first time, you’ll be prompted to authenticate:()
-
Sign in with your Google account: This grants you access to Gemini 2.5 Pro with the following free-tier limits:
-
Up to 60 requests per minute
-
Up to 1,000 requests per day
-
-
Use an API Key: For higher usage limits or specific model access, you can generate an API key from Google AI Studio and set it as an environment variable:
export GEMINI_API_KEY="your-api-key"
This method is ideal for headless servers or scripting environments.
🧪 Running Your First Command
Once authenticated, you can start interacting with Gemini CLI. Here are some ways to use it:
Interactive Mode
Launch Gemini CLI in interactive mode:
gemini
In this mode, you can enter natural language prompts directly. For example:
│ > write a script in a file named p1.py Hello World.
One-Liner Prompt
Run a single prompt without entering interactive mode:
gemini -p "What is fine tuning?"
(base) ~/Documents/projects/geminit-project ᐅ gemini -p "What is fine tuning?"
Fine-tuning is a machine learning technique where a pre-trained model, which has been trained on a large general dataset, is further trained on a smaller, more specific dataset. This process adapts the model to a specialized task.
Here's a breakdown of the process:
1. **Select a pre-trained model**: Start with a model that has already been trained on a large, general dataset.
2. **Prepare a specialized dataset**: Collect a smaller, labeled dataset that is specific to the desired task.
3. **Continue training**: The pre-trained model's existing parameters are used as a starting point, and the model is then trained further on the specialized dataset.
4. **Evaluate**: The performance of the fine-tuned model is evaluated on a separate set of data to see how well it performs on the new task.
The main benefits of fine-tuning are:
* **Cost and resource efficiency**: It's generally faster and requires less computational power and data than training a model from scratch.
* **Improved performance**: Fine-tuned models can achieve high accuracy on specialized tasks.
* **Better performance on smaller datasets**: It helps the model generalize better by leveraging the knowledge from the large, pre-trained dataset.
* **Democratization of machine learning**: It makes advanced AI models more accessible.
Shell Commands
Execute shell commands within Gemini CLI by prefixing them with an exclamation mark:
!ls -la
🧰 Exploring Built-in Tools
Gemini CLI comes with several built-in tools to enhance your workflow:
-
/memory: View or reset the conversation memory.
-
/tools: List available tools like Google Search and Code Interpreter.
-
/mcp: Manage Multi-Context Prompting (MCP) servers.
These tools allow you to customize and extend the capabilities of Gemini CLI to suit your development needs.
📁 Working with Projects
You can use Gemini CLI with both new and existing projects:
Starting a New Project
Create a new directory and launch Gemini CLI:()
mkdir new-project
cd new-project
gemini
Then, you can prompt Gemini to assist with your project setup.
Using an Existing Project
Navigate to your project directory and start Gemini CLI:()
cd existing-project
gemini
You can then ask Gemini to analyze or modify your existing codebase.