DEV Community

Cover image for Gemini & Gemini CLI — Beginner Learning Notes
Abhishek Gupta
Abhishek Gupta

Posted on Edited on

Gemini & Gemini CLI — Beginner Learning Notes

Chapter 1: Introduction to Gemini CLI

1. What is Artificial Intelligence (AI)?

Artificial Intelligence (AI) is a technology that enables computers to perform tasks that normally require human intelligence.

Examples include:

  • Understanding questions.
  • Generating text and code.
  • Recognizing patterns.
  • Explaining concepts.
  • Helping solve problems.

2. What is Gemini?

Gemini is a family of AI models developed by Google.

An AI model processes input and generates a response based on its training and the information available to it.

Example:

You ask:

Explain JavaScript functions in simple English.

Gemini can explain functions, provide examples, and help you understand how they work.

3. What is Gemini CLI?

Gemini CLI is an open-source AI assistant that lets developers interact with Gemini through a command-line interface.

CLI stands for Command-Line Interface.

Instead of using only a web-based chat interface, you can work with Gemini from your terminal and use its available tools to interact with your development project.

For example, you can ask Gemini CLI to:

  • Explain your project structure.
  • Create or edit source files.
  • Find bugs in your code.
  • Help write tests.
  • Run commands when permitted.
  • Generate documentation.
  • Help you understand an unfamiliar codebase.

Example prompt:

Explain the folder structure of this project.
Identify the main entry point.
Do not modify any files.
Enter fullscreen mode Exit fullscreen mode

Gemini CLI can inspect relevant project files using its available tools and permissions.

4. How is Gemini CLI different from a normal AI chatbot?

A normal chatbot is primarily designed for conversations. Gemini CLI is designed to bring AI assistance into a terminal-based development workflow.

Gemini chat Gemini CLI
Usually accessed through a chat interface Accessed through a terminal
Explains concepts and generates code Can work with project files using tools
You often copy code into your editor It can edit files when authorized
Works with information you provide Can inspect relevant local project information
Mainly conversation-oriented Supports tool-assisted development tasks

Important: Gemini is the AI model family. Gemini CLI is the tool used to interact with Gemini from the command line.

5. Why do developers use Gemini CLI?

Imagine you have an existing React project with many files. You want to understand how the application works.

Without an AI coding assistant, you may need to inspect every relevant file manually.

With Gemini CLI, you can ask:

Study this project and explain:
1. The main application entry point.
2. The components folder.
3. How routing works.
4. How API requests are handled.
5. Where the application state is managed.

Explain everything in beginner-friendly language.
Do not modify any files.
Enter fullscreen mode Exit fullscreen mode

This can help you understand the project faster. However, you should verify its explanations against the actual code.

6. What are the limitations of Gemini CLI?

Gemini CLI is helpful, but it is not perfect.

  • It can generate incorrect code.
  • It can misunderstand project requirements.
  • It can make unwanted changes if instructions are unclear.
  • It may not have access to every file or tool.
  • It may require authentication and an internet connection.
  • Its available features depend on the installed version, account, configuration, and permissions.

Rule: Never accept AI-generated code blindly. Review it, test it, and understand the changes.

Quick revision

  • AI: Technology that enables computers to perform intelligent tasks.
  • Gemini: Google's family of AI models.
  • Gemini CLI: A terminal-based AI assistant.
  • CLI: Command-Line Interface.
  • Prompt: An instruction or question given to an AI.
  • Codebase: The collection of source code and related files in a project.

Interview questions

Q1. What is Gemini CLI?

Gemini CLI is an open-source, terminal-based AI assistant that allows developers to interact with Gemini and perform coding tasks using available tools.

Q2. What does CLI stand for?

CLI stands for Command-Line Interface. It allows users to interact with a computer or program by entering text commands.

Q3. How is Gemini CLI useful to developers?

It can help developers understand codebases, generate and edit files, debug problems, write tests, and create documentation.

Q4. Does Gemini CLI always generate correct code?

No. It can make mistakes, so developers should review the generated code and run appropriate tests.


Chapter 2: Terminal and Command-Line Basics

1. What is a terminal?

A terminal is an application that lets you interact with your computer by typing commands.

Examples:

  • Windows: PowerShell or Windows Terminal.
  • Linux: Terminal.
  • macOS: Terminal.

2. What is a shell?

A shell is a program that interprets commands and executes them or passes them to the appropriate system tools.

For example, Bash and Zsh are common Linux/macOS shells. PowerShell is commonly used on Windows.

Remember the difference:

  • Terminal: The application where you enter commands.
  • Shell: The program that interprets those commands.

3. Essential terminal commands

Command Purpose
pwd Show the current directory on Linux/macOS
ls List files on Linux/macOS
dir List files in PowerShell
cd folder-name Enter a directory
mkdir project-name Create a directory
node --version Check the Node.js version
npm --version Check the npm version

Some commands differ between operating systems and shells.

4. Working with a project directory

Suppose you want to create a folder for learning Gemini CLI.

mkdir learning-project
cd learning-project
Enter fullscreen mode Exit fullscreen mode

What happens?

  1. mkdir learning-project creates a directory.
  2. cd learning-project moves into that directory.

Start Gemini CLI from the project directory:

gemini
Enter fullscreen mode Exit fullscreen mode

This helps the tool work with the intended project context.

5. Why does the current directory matter?

The current directory is the location in which your shell is currently working.

When you start Gemini CLI from a project directory, its access to project files and instruction files depends on the working directory, configuration, permissions, and instruction-loading rules.

For example, starting it inside your React project is more useful when you want help with that React project than starting it from an unrelated directory.

Best practice: Check your current directory before asking an AI assistant to modify files.

Practice task

  1. Open your terminal.
  2. Create a folder named gemini-practice.
  3. Enter that folder.
  4. Check your current location.
  5. Start Gemini CLI if it is installed.

Interview questions

Q1. What is a terminal?

A terminal is an application that provides a text-based interface for interacting with a computer.

Q2. What is a shell?

A shell interprets commands and executes them or invokes the required programs.

Q3. Why should you start Gemini CLI from the project directory?

It helps Gemini CLI work in the intended project context and locate relevant files according to its configuration and permissions.


Chapter 3: Installing and Starting Gemini CLI

1. What is Node.js?

Node.js is a JavaScript runtime that allows JavaScript to run outside a web browser.

It is required for the npm-based Gemini CLI installation method described in these notes.

Official website: https://nodejs.org/

2. What is npm?

npm is a package manager used to install and manage JavaScript packages.

A package manager helps developers install software and its dependencies.

3. Check your installation

Run these commands:

node --version
npm --version
Enter fullscreen mode Exit fullscreen mode

If both commands return version numbers, Node.js and npm are available in your terminal.

If either command is unavailable, check your installation and PATH configuration.

4. Install Gemini CLI using npm

Run:

npm install -g @google/gemini-cli
Enter fullscreen mode Exit fullscreen mode

Understand the command:

  • npm: Runs the package manager.
  • install: Installs a package.
  • -g: Requests a global installation.
  • @google/gemini-cli: Identifies the package.

Verify the installation:

gemini --version
Enter fullscreen mode Exit fullscreen mode

Start the tool:

gemini
Enter fullscreen mode Exit fullscreen mode

Follow the authentication instructions displayed on your screen.

5. What is global installation?

A global installation makes a package's command available from different directories, subject to your system's PATH and installation configuration.

This is useful for command-line tools that you want to run across multiple projects.

6. Linux installation using Snap

Snap is a package system available on supported Linux distributions.

Check Snap:

snap version
Enter fullscreen mode Exit fullscreen mode

Install the package:

sudo snap install gemini-cli
Enter fullscreen mode Exit fullscreen mode

Verify and start:

gemini --version
gemini
Enter fullscreen mode Exit fullscreen mode

Important: This Snap package is community-maintained, not an official Google-published package. Snap may also restrict access to some files.

For beginners, the npm method is a straightforward option when Node.js and npm are configured correctly.

7. Common installation problems

Problem What to check
node not found Install Node.js and check PATH
npm not found Check Node.js installation
gemini not found Check installation output and executable path
Permission denied Check npm configuration and file permissions
Login fails Check network and supported authentication options
Project files are inaccessible Check the current directory and filesystem permissions

Avoid immediately using sudo to solve npm global-installation errors. Fix the underlying permission or configuration problem instead.

8. Authentication

Authentication establishes that you are authorized to use a service.

On first launch, Gemini CLI may offer authentication options. Follow the current instructions displayed by your installed version.

Available options can depend on your account, location, and configuration.

Official documentation: https://geminicli.com/docs/

Practice task

Install Gemini CLI and confirm that:

  • Node.js works.
  • npm works.
  • gemini --version returns a version.
  • gemini starts successfully.
  • You can complete a supported authentication flow.

Chapter 4: Understanding Prompts

1. What is a prompt?

A prompt is the instruction or question you give an AI assistant.

The quality of your prompt affects how clearly the assistant understands your requirements.

2. Weak prompt vs. good prompt

Weak prompt:

Make a calculator website.
Enter fullscreen mode Exit fullscreen mode

The instruction does not explain what kind of website is needed, which technologies to use, or what features to include.

Better prompt:

Build a complete, responsive calculator web application.

Requirements:

1. Technologies
- Use HTML, CSS, and vanilla JavaScript.
- Do not use external libraries or frameworks.
- Separate the application into index.html, style.css, and script.js.

2. Calculator functionality
- Support addition, subtraction, multiplication, and division.
- Support decimal numbers and negative numbers.
- Include Clear (C), Delete (⌫), and Equals (=) buttons.
- Follow standard arithmetic operator precedence.
- Support keyboard input.
- Prevent division by zero and display a helpful error message.
- Handle invalid expressions safely.

3. UI and design
- Create a clean, modern, professional calculator interface.
- Use a dark theme with subtle blue accents.
- Make buttons easy to identify and use.
- Display the current expression and result clearly.
- Support desktop, tablet, and mobile screens.
- Include hover, focus, and pressed states.

4. Code quality
- Use readable, maintainable JavaScript.
- Separate UI updates from calculation logic where practical.
- Do not use eval() to calculate expressions.
- Avoid unnecessary code and dependencies.
- Include helpful comments for important logic.

5. Testing
- Test addition, subtraction, multiplication, and division.
- Test decimals, negative numbers, and operator precedence.
- Test division by zero, invalid input, Clear, and Delete.
- Fix any issues found during testing.

6. Completion report
- List the files created or modified.
- Explain how to run the application.
- Summarize the tests performed and their actual results.
- Report any unfinished features or known limitations.

First inspect the existing project, if one exists. Then implement the calculator, run the available checks, and summarize the completed work. Do not claim a test passed unless you actually ran it.
Enter fullscreen mode Exit fullscreen mode

The second prompt gives the AI clearer requirements.

3. A simple prompt-writing formula

Use these four elements:

Goal + Context + Requirements + Restrictions

  1. Goal: What do you want to accomplish?
  2. Context: What project or files are involved?
  3. Requirements: What must the result include?
  4. Restrictions: What must not be changed?

Example:

Goal:
Fix the login form validation.

Context:
This is an existing React application.

Requirements:
Validate the email and password fields.
Display useful error messages.
Keep the current design.

Restrictions:
Do not change the authentication API.
Do not modify unrelated files.
Enter fullscreen mode Exit fullscreen mode

4. Prompting tips

  • Explain your goal clearly.
  • Mention the technology stack.
  • Provide relevant error messages.
  • Describe the expected behavior.
  • Specify what should not change.
  • Ask for explanations when learning.
  • Request tests when appropriate.
  • Review changes before accepting them.

Interview questions

Q1. What is prompt engineering?

Prompt engineering is the practice of writing and refining instructions so that an AI system can better understand the task and produce useful results.

Q2. What makes a prompt effective?

A useful prompt clearly states the goal, provides relevant context, lists requirements, and specifies important restrictions.

Q3. Can a detailed prompt guarantee a correct result?

No. A detailed prompt reduces ambiguity, but the result must still be checked and tested.


Chapter 5: Using Gemini CLI with an Existing Project

1. First understand the project

Do not immediately ask the AI to rewrite your entire application.

Start by understanding the existing codebase.

Analyze this project.

Explain:
1. The folder structure.
2. The main entry point.
3. The technologies used.
4. How the application starts.
5. How the frontend communicates with the backend.

Use simple English.
Do not modify any files.
Enter fullscreen mode Exit fullscreen mode

2. Generate a new feature

After understanding the project, ask for a specific task.

Add a search field to the existing user list.

Requirements:
- Search users by name.
- Update results as the user types.
- Follow the existing coding style.
- Keep the current layout.
- Do not modify unrelated features.
- Explain the changes.
Enter fullscreen mode Exit fullscreen mode

3. Debug an error

When something breaks, ask the AI to investigate the cause before changing code.

Investigate this error.

First:
1. Identify the likely cause.
2. Explain why it happens.
3. Suggest the smallest suitable fix.

Then apply the fix only if appropriate.
Run the relevant tests if available.
Do not change unrelated files.
Enter fullscreen mode Exit fullscreen mode

4. Review changes

After the assistant modifies code, check:

  • Which files changed?
  • Does the code solve the original problem?
  • Were unrelated files modified?
  • Are there new errors?
  • Do existing tests still pass?
  • Are there security or performance concerns?

Important: You remain responsible for the code, even when an AI assistant writes it.


Chapter 6: Understanding GEMINI.md

1. What is GEMINI.md?

GEMINI.md is a Markdown file that provides project-specific instructions and context to Gemini CLI.

It can help the assistant follow the project's conventions across multiple tasks.

2. Example

# Project Instructions

## Technology
- Use JavaScript for frontend code.
- Follow the existing framework and project structure.

## Coding Style
- Write small, readable functions.
- Use meaningful variable names.
- Avoid unnecessary duplication.

## Project Rules
- Do not modify unrelated files.
- Explain important changes.
- Run relevant tests when possible.
Enter fullscreen mode Exit fullscreen mode

3. Why is it useful?

Without project instructions, you may need to repeat the same requirements in multiple prompts.

A suitable GEMINI.md file provides reusable guidance.

However, it does not guarantee perfect compliance. You should still review the generated code.

Interview question

What is the purpose of GEMINI.md?

It provides reusable project instructions and context that help Gemini CLI understand the project's conventions and requirements.

Official documentation: https://geminicli.com/docs/


Chapter 7: Commands and Tools

1. Gemini CLI slash commands

Common commands include:

Command Purpose
/help Show help information
/tools Inspect available tools
/clear Clear conversation context
/quit Exit, where supported

The available commands may vary between versions. Use /help to check the commands supported by your installation.

2. Terminal commands vs. slash commands

These are different types of commands.

Terminal command:

npm --version
Enter fullscreen mode Exit fullscreen mode

This is executed by your shell.

Gemini CLI slash command:

/help
Enter fullscreen mode Exit fullscreen mode

This is entered inside the Gemini CLI interface.

Do not assume that every terminal command is a Gemini CLI slash command.

3. What are tools?

Tools allow an AI assistant to perform actions beyond generating text.

Depending on the configuration, available tools may allow Gemini CLI to inspect files, edit code, run commands, or access other resources.

Tool access may be restricted by permissions and configuration.

4. Why are permissions important?

Some actions only read information. Others can change files or execute commands.

Before approving an unfamiliar or destructive action:

  1. Understand what it will do.
  2. Check which files or resources it affects.
  3. Confirm that the action is appropriate.
  4. Keep a backup or Git commit when necessary.

Chapter 8: Safety and Best Practices

AI-assisted development introduces risks if generated commands or code are trusted without review.

Important rules

  • Never share passwords, API keys, or access tokens in prompts.
  • Review file changes before accepting them.
  • Understand commands before allowing them to run.
  • Avoid approving destructive operations without checking their impact.
  • Keep important work backed up or committed to Git.
  • Run tests after making changes.
  • Inspect generated code for security issues.
  • Verify third-party packages before installing them.

Interview question

Why should developers review AI-generated code?

Because AI can produce incorrect, insecure, inefficient, or irrelevant code. Reviewing and testing the result helps ensure it meets the requirements.


Chapter 9: Interview Revision

Important questions and answers

1. What is Gemini CLI?

An open-source terminal-based AI assistant for working with Gemini and performing development tasks using available tools.

2. What does CLI stand for?

Command-Line Interface.

3. What is the difference between Gemini and Gemini CLI?

Gemini is Google's family of AI models, while Gemini CLI is a terminal-based tool for interacting with Gemini.

4. What is a prompt?

An instruction or question given to an AI assistant.

5. What is prompt engineering?

The practice of designing clear instructions to help an AI understand and perform a task.

6. What is Node.js?

A JavaScript runtime that allows JavaScript to execute outside a web browser.

7. What is npm?

A package manager used to install and manage JavaScript packages.

8. What does npm install -g mean?

It installs a package globally, making its command available from different directories when the environment is configured correctly.

9. What is authentication?

The process of verifying identity or establishing authorized access to a service.

10. What is GEMINI.md?

A Markdown file containing project-specific instructions and context for Gemini CLI.

11. Why should Gemini CLI be started in the project directory?

To work in the intended project context and make relevant files available according to the tool's permissions and configuration.

12. Does Gemini CLI replace a developer?

No. It assists with development, but developers must understand requirements, review code, test results, and make technical decisions.

13. What should you do before allowing the AI to edit an existing project?

Understand the task, define restrictions, review the planned changes, and protect important work with version control or backups.

14. How can you improve an incorrect AI-generated answer?

Provide clearer context, specify the expected behavior, share relevant errors, and ask for a focused correction. Then verify the result.


Chapter 10: Practical Learning Checklist

Use this checklist to measure your progress.

  • [ ] Explain Gemini and Gemini CLI in your own words.
  • [ ] Explain the difference between a terminal and a shell.
  • [ ] Install Node.js and npm.
  • [ ] Install and launch Gemini CLI.
  • [ ] Complete a supported authentication method.
  • [ ] Ask Gemini CLI to explain a project without editing files.
  • [ ] Write a clear prompt using goal, context, requirements, and restrictions.
  • [ ] Create or modify a small feature.
  • [ ] Ask Gemini CLI to investigate and fix a bug.
  • [ ] Understand the purpose of GEMINI.md.
  • [ ] Inspect file changes and run relevant tests.
  • [ ] Explain important concepts without looking at the notes.

Final Revision

Remember these core ideas:

  • Gemini is the AI model family.
  • Gemini CLI brings AI assistance into the terminal.
  • Prompts communicate your requirements.
  • Project context helps the AI understand what it needs to do.
  • GEMINI.md provides reusable project instructions.
  • Tools enable actions such as inspecting files or running commands.
  • Permissions control which actions are allowed.
  • Testing and code review remain essential.

Learning strategy: Understand one concept, try one practical example, and then answer its interview question without looking at the notes.

Top comments (0)