An AI Terminal Assistant
At Your Service
© Lead Image © Milosh Kojadinovich, 123RF.com
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)
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 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.
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
(incl. VAT)
Buy Linux Magazine
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.
News
-
Microsoft Issues Warning About Linux Vulnerability
The company behind Windows has released information about a flaw that affects millions of Linux systems.
-
Is AI Coming to Your Ubuntu Desktop?
According to the VP of Engineering at Canonical, AI could soon be added to the Ubuntu desktop distribution.
-
Framework Laptop 13 Pro Competes with the Best
Framework has released what might be considered the MacBook of Linux devices.
-
The Latest CachyOS Features Supercharged Kernel
The latest release of CachyOS brings with it an enhanced version of the latest Linux kernel.
-
Kernel 7.0 Is a Bit More Rusty
Linux kernel 7.0 has been released for general availability, with Rust finally getting its due.
-
France Says "Au Revoir" to Microsoft
In a move that should surprise no one, France announced plans to reduce its reliance on US technology, and Microsoft Windows is the first to get the boot.
-
CIQ Releases Compatibility Catalog for Rocky Linux
The company behind Rocky Linux is making an open catalog available to developers, hobbyists, and other contributors, so they can verify and publish compatibility with the CIQ lineup.
-
KDE Gets Some Resuscitation
KDE is bringing back two themes that vanished a few years ago, putting a bit more air under its wings.
-
Ubuntu 26.04 Beta Arrives with Some Surprises
Ubuntu 26.04 is almost here, but the beta version has been released, and it might surprise some people.
-
Ubuntu MATE Dev Leaving After 12 years
Martin Wimpress, the maintainer of Ubuntu MATE, is now searching for his successor. Are you the next in line?
