The Gemini CLI is a command-line interface that allows you to interact with Google’s Gemini models directly from your terminal. It provides a convenient way to experiment with Gemini, test prompts, and build powerful shell scripts that leverage the capabilities of large language models.
This guide will walk you through the process of installing and configuring the Gemini CLI.
2 Prerequisites: Node.js Installation
The Gemini CLI is distributed as an npm package, so you need to have Node.js and npm installed on your system. The recommended way to install Node.js is by using the Node Version Manager (nvm).
Code
# Download and install nvmcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash# Activate nvm for the current shell sessionsource ~/.nvm/nvm.sh# Install the latest stable version of Node.jsnvm install 20# Verify the installationnode -vnpm -v
3 Installing the Gemini CLI
Once you have Node.js and npm ready, you can install the Gemini CLI globally on your system.
Code
# Install the Gemini CLI packagenpm install -g @google/gemini-cli
3.1 Upgrading the Gemini CLI
To ensure you have the latest features and bug fixes, you can upgrade the package from time to time.
Code
# Upgrade the Gemini CLI to the latest versionnpm upgrade -g @google/gemini-cli
4 Configuration
To use the Gemini CLI, you need to authenticate with your Google account and configure your project.
4.1 Login with Your Google Account
You can either log in with your Google Cloud account or use an API key.
4.1.1 Option 1: Login with Google Cloud Account
Code
# Set your Google Cloud project IDexport GOOGLE_CLOUD_PROJECT="your-google-cloud-project-id"
or save the GOOGLE_CLOUD_PROJECT into environment variable.So that do not need to re enter everytime
Alternatively, you can use an API key for authentication.
Code
# Set your Gemini API key as an environment variableexport GEMINI_API_KEY="your-gemini-api-key"
4.2 Set the Location
You also need to specify the Google Cloud location where your resources will be managed.
Code
# Set the Google Cloud locationexport GOOGLE_CLOUD_LOCATION='us-central1'
5 Running the Gemini CLI
Once everything is set up, you can run the Gemini CLI to start interacting with the models.
Code
# Run the Gemini CLIgemini
6 Running the Gemini CLI with agreement to all access
Code
# Run the Gemini CLIgemini --yolo
7 Conclusion
The Gemini CLI is a powerful tool for developers and enthusiasts who want to explore the capabilities of Google’s Gemini models from the command line. With its simple installation and configuration process, you can quickly start leveraging the power of generative AI in your daily workflows.
---title: "Getting Started with the Gemini CLI"execute: warning: false error: false eval: falseformat: html: toc: true toc-location: right code-fold: show code-tools: true number-sections: true code-block-bg: true code-block-border-left: "#31BAE9"---# Introduction to the Gemini CLIThe Gemini CLI is a command-line interface that allows you to interact with Google's Gemini models directly from your terminal. It provides a convenient way to experiment with Gemini, test prompts, and build powerful shell scripts that leverage the capabilities of large language models.This guide will walk you through the process of installing and configuring the Gemini CLI.# Prerequisites: Node.js InstallationThe Gemini CLI is distributed as an npm package, so you need to have Node.js and npm installed on your system. The recommended way to install Node.js is by using the Node Version Manager (nvm).```{python}# Download and install nvmcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash# Activate nvm for the current shell sessionsource ~/.nvm/nvm.sh# Install the latest stable version of Node.jsnvm install 20# Verify the installationnode -vnpm -v```# Installing the Gemini CLIOnce you have Node.js and npm ready, you can install the Gemini CLI globally on your system.```{python}# Install the Gemini CLI packagenpm install -g @google/gemini-cli```## Upgrading the Gemini CLITo ensure you have the latest features and bug fixes, you can upgrade the package from time to time.```{python}# Upgrade the Gemini CLI to the latest versionnpm upgrade -g @google/gemini-cli```# ConfigurationTo use the Gemini CLI, you need to authenticate with your Google account and configure your project.## Login with Your Google AccountYou can either log in with your Google Cloud account or use an API key.### Option 1: Login with Google Cloud Account```{python}# Set your Google Cloud project IDexport GOOGLE_CLOUD_PROJECT="your-google-cloud-project-id"```or save the GOOGLE_CLOUD_PROJECT into environment variable.So that do not need to re enter everytime#### check using zsh or bash```{python}echo $SHELL```#### for zsh```{python}echo 'export GOOGLE_CLOUD_PROJECT="your-google-cloud-project-id"'>>~/.zshrcsource ~/.zshrc```#### for bash```{python}echo 'export GOOGLE_CLOUD_PROJECT="your-google-cloud-project-id"'>>~/.bashrcsource ~/.bashrc```#### check wheather added or not```{python}echo $GOOGLE_CLOUD_PROJECT```### Option 2: Login with API KeyAlternatively, you can use an API key for authentication.```{python}# Set your Gemini API key as an environment variableexport GEMINI_API_KEY="your-gemini-api-key"```## Set the LocationYou also need to specify the Google Cloud location where your resources will be managed.```{python}# Set the Google Cloud locationexport GOOGLE_CLOUD_LOCATION='us-central1'```# Running the Gemini CLIOnce everything is set up, you can run the Gemini CLI to start interacting with the models.```{python}# Run the Gemini CLIgemini```# Running the Gemini CLI with agreement to all access```{python}# Run the Gemini CLIgemini --yolo```# ConclusionThe Gemini CLI is a powerful tool for developers and enthusiasts who want to explore the capabilities of Google's Gemini models from the command line. With its simple installation and configuration process, you can quickly start leveraging the power of generative AI in your daily workflows.# Reference- [Gemini CLI on GitHub](https://github.com/google-gemini/gemini-cli)- [Node.js Downloads](https://nodejs.org/en/download)