Tuesday, September 30, 2025

Google Cloud Learning - Gemini CLI basics

# option 1: install Gemini CLI

npm install -g @google/gemini-cli

# .. and then run

gemini


# option 2: run without installing Gemini CLI


npx https://github.com/google-gemini/gemini-cli


gemini --version



Login via Google can be used for initial personal tests 


Settings are applied with the following precedence (Cloud Shell only makes User settings available):


System: /etc/gemini-cli/settings.json (applies to all users, overrides user and workspace settings).

Workspace: .gemini/settings.json (overrides user settings).

User: ~/.gemini/settings.json.



Typical JSON is as below 


{

  "theme": "Default",

  "selectedAuthType": "oauth-personal" or "cloud-shell"

}



Sample query as below 


Give me a famous quote on Artificial Intelligence and who said that?


You will notice that our query resulted in a GoogleSearch tool (an in-built tool in Gemini CLI) that got invoked. In other words, you have already exercised one of Gemini CLIs powerful in-built tools namely GoogleSearch that grounds its responses based on information that it gets from the web. You will learn more about Tools in the next section.


A quick way to understand Gemini CLI and the various commands that it supports is to type /help



gemini --help => For help 



Currently, at the time of writing this writing, these are the only two models supported. By default the Gemini 2.5 Pro model is used, but if you would like to use the Flash Model, you can do that at the time of starting Gemini CLI via the -m parameter as shown below:


gemini -m "gemini-2.5-flash"


Non-interactive mode

An interesting option is to run Gemini CLI in a non-interactive mode. This means that you directly provide it the prompt and it will go ahead and respond to it, without the Gemini CLI interactive terminal opening up. This is very useful if you plan to use Gemini CLI in an automated fashion as part of the script or any other automation process. You use the -p parameter to provide the prompt to Gemini CLI as shown below:


gemini -p "What is the gcloud command to deploy to Cloud Run"


To get a list of current Built-in Tools, invoke the /tools command as shown below:


While there is a --yolomode available when you start the CLI (not typically recommended), you will find that Gemini CLI will prompt you for permission to run the tool that it has chosen. You can refuse permission, or let it run once or give it blanket permission to always run. You are and should be in full control of things.



A typical example is like below 


Search for the latest headlines today in the world of finance and save them in a file named finance-news-today.txt



The first thing it does is that it invokes the GoogleSearch tool to search the web.

Once that is done, it is ready to write this to the file and it will use the WriteFile tool, but since that is a sensitive operation (write), it will ask for your permission. You can decide the permission type i.e. allow once , allow always, etc. Go ahead and select allow once for now.

This will then write the information to the file and a success message 


read the contents of @finance-news-today.txt => this can be used to read the contents of the file. 


No comments:

Post a Comment