An AI Terminal Assistant

At Your Service

© Lead Image © Milosh Kojadinovich, 123RF.com

© Lead Image © Milosh Kojadinovich, 123RF.com

Article from Issue 303/2026
Author(s):

Gemini CLI helps you write, debug, and test your code, all from the command line.

Artificial intelligence (AI) is revolutionizing the way we interact with the Linux terminal. Google's Gemini command-line interface (CLI) [1], an AI agent, brings the power of Gemini to the command line. Gemini CLI crawls your code trying to understand its logic and then shows you how to improve your code.

In this article, I'll show you how to install Gemini CLI on a Ubuntu 22.04 system. I'll then use Gemini CLI to write, debug, and test my code based on my daily workflow to help you understand the process.

Prerequisites and System Preparation

To onboard Gemini CLI on an Ubuntu machine, you will need to install Node.js v20 or higher (as of October 2025), because Gemini CLI uses Node Package Manager (npm) for installation. I have Ubuntu 22.04 installed on my system, so I can verify that Node.js is installed with

$ node -v

If Node.js isn't present on your system, you can install the latest version from Nodejs.org [2].

You'll also need a personal Google account to natively install Google Gemini on your machine. Gemini CLI's free tier offers 60 requests per minute and 1,000 requests per day. If you need more, you can opt for Gemini Pro 2.5, which provides a one-million-token context window.

Getting Started

You have two options for running Gemini on Linux. If you're just trying out Gemini CLI, you can avoid a global installation by using npx to run it instantly:

$ npx @google/gemini-cli

If you go this route, you'll need to run the above command every time you want to use Gemini CLI. However, after the first time, it will go directly to the Gemini console. Note that you'll directly see the login window if you use the npx install process.

For a global installation, you can use npm:

$ npm install -g @google/gemini-cli

Once Gemini CLI is installed globally, enter gemini at the terminal prompt to access the login window (Figure 1). During the initial launch, you'll be prompted to authenticate and given a choice of three login options:

  • A personal Google account
  • A Gemini API key (best if you're developing some applications)
  • The Vertex AI development platform (specifically for production workloads)
Figure 1: The Gemini CLI login prompt shows you three options.

If you choose to log in with a Gemini API key [3], you can create a key with Google AI Studio. After the first time, you can set the key as an environment variable from your terminal using

$ export GEMINI_API_KEY="your_api_key"

If you're looking for an enterprise solution, Vertex AI is your best option (see Vertex AI's official documentation [4] for more information).

For learning purposes, I recommend using the Google account, because it is the easiest method. Clicking on Login with Google (Figure 1) will take you to a browser window where you'll be asked to log in with your Google account to gain access to the free tier.

After logging in, enter

$ gemini --version

to confirm installation and diagnose any missing dependencies. Now that you have it installed, I'll show you Gemini CLI in action with some examples.

Managing a Codebase

After authentication, the Gemini CLI prompt looks like a typical shell. Now the real fun begins. Starting in my codebase directory, I asked Google Gemini to tell me the function of one of my project files using the following prompt:

> Hey Gemini, what does the file script.js do in my project?

Gemini CLI responded by reading script.js, analyzing it, and generating a clear English summary as shown in Figure 2. This is particularly useful if you revisit a project after time away. You can also use Gemini CLI to suggest improvements to your code:

> Can you suggest some error-handling code for script.js?
Figure 2: Gemini CLI analyzes your code and shows the logic behind a project file.

Figure 3 shows how Gemini responded to my prompt by suggesting how to improve the code and gave me a new code snippet. Gemini CLI will then prompt you to approve the changes. Be careful: You should always review the code before applying it.

Figure 3: Gemini CLI suggests code improvement or feature additions to an existing file.

You can even ask Gemini to crawl your project codebase, detect errors, and provide suggestions. Within seconds, Gemini will start analyzing your files and identifying those files that need improvement. Again, you must confirm the changes before Gemini CLI will apply them. However, you can select the Yes, allow always option to automatically apply changes (again, proceed with caution when choosing this option).

Buy this article as PDF

Download Article PDF now with Express Checkout
Price $2.95
(incl. VAT)

Buy Linux Magazine

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News