iT邦幫忙

2025 iThome 鐵人賽

DAY 27
0

開啟

終端機(找到自己想用的路徑)輸入:

gemini

關閉

兩下 ctrl c or 指令:

/quit

退出後會有結算介面: 會顯示這輪任務用了多少 Token

帳號

一般使用: Google 帳號

付費大量使用: API Key

/auth

指令列表

/help

MCP(Model Context Protocol)是 AI 和 AI 溝通的橋樑,例如我們在 Gemini CLI 設定好 GitHub 的 MCP 後,Gemini CLI 就能直接跟 GitHub 溝通,並且幫我們完成操作設定

列出所有MCP sever:

/mcp

設置 MCP


終端機輸入指令 ~/.gemini/settings.json

會打開設置擋 EX:

{
  "ide": {
    "hasSeenNudge": true
  },
  "security": {
    "auth": {
      "selectedType": "oauth-personal"
    }
  },
  "ui": {
    "theme": "Default"
  }
}

範例: Github MCP

我們要新增這塊

,
  "mcpServers": {
       "github": {
            "httpUrl": "https://api.githubcopilot.com/mcp/",
            "headers": {
                "Authorization": "你的GitHub的Personal access tokens (classic)金鑰"
            },
            "timeout": 5000
       }
  }

Gemini Extensions = 無限擴充能力

Google:一個好的工具應該要是萬能的

你可能會想都是 AI 使用工具跟 mcp有什麼差別

那我只能說很可怕,一個擴充就包含:

1000032458.jpg

mcp、基本命令(擴充的指令)、上下文(系統提示詞) → 這些讓你可以使用自然語言,讓AI自己用,更不用說用yolo mode…

安裝擴充功能比 MCP 還容易,只需在命令列中輸入:

gemini extensions install <新增您的 GitHub URL 或本機路徑>

目前合作的工具:

https://blog.google/technology/developers/gemini-cli-extensions/

範例官方擴充:

https://geminicli.com/extensions/browse/

  1. 點進去
  2. 按右下複製
  3. 使用系統管理員權限打開 CLI ,貼上

#Chrome DevTools MCP 是一個由 Google 推出的新型開發者工具協定,主要目的是讓 AI 助手或自動化代理能直接在 Chrome 瀏覽器中操控、偵錯和最佳化網頁,而不再只是靜態地分析程式碼。

更可怕的是,這個擴充你可以自己做一個,嵌入任何工具進去。

詢問特定檔案

#要在同一個資料夾下

@sample_file.md

搜尋

可以利用搜尋功能使用最新資料

Example Prompt: 現在為我搜尋Google 推出的Gemini CLI,並依照 @index.md 的文章格式,寫一篇教學文章

index.md

成果:

---
title: "Google Gemini CLI 教學"
date: 2025-10-08
author: "Gemini 使用者"
description: "這是一篇關於如何安裝與使用 Google Gemini CLI 的教學文章,帶您一步步了解這個強大的 AI 工具。"
tags:
  - Gemini
  - CLI
  - Google
  - AI
  - 教學
---

# Google Gemini CLI 教學

歡迎閱讀這篇教學文章!在這裡,我們將會一步步帶您了解如何安裝及使用 Google 推出的 Gemini CLI,一個能將 Gemini 2.5 Pro 的強大功能帶入您終端機的工具。

這篇文章是為所有希望在命令列環境中提升開發效率的開發者所設計。

## 先決條件

在開始之前,請確保您已經準備好以下項目:

*   **Node.js**:已安裝 Node.js v18 或更高版本。
*   **終端機**:熟悉使用終端機或命令提示字元。
*   **Google 帳號**:一個個人的 Google 帳號用於免費層級的認證。

## 步驟一:安裝 Gemini CLI

這是第一個步驟。我們將透過 `npx` 來安裝並執行 Gemini CLI,這能確保您總是使用最新版本。

1.  開啟您的終端機或命令提示字元。
2.  執行以下指令:
    ```bash
    npx https://github.com/google-gemini/gemini-cli
    ```
> **提示**:您也可以使用 `npm install -g @google/gemini-cli` 進行全域安裝,但建議使用 `npx` 以避免版本衝突並確保執行的是最新代碼。

## 步驟二:進行使用者認證

安裝指令執行後,CLI 會自動引導您進行認證。

1.  執行 `npx` 指令後,CLI 會提示您登入。
2.  它將在您的瀏覽器中開啟一個認證頁面,請登入您的 Google 帳號。
3.  成功登入後,您的終端機將完成認證,並準備好接收指令。

## 步驟三:開始與 Gemini 互動

現在是時候與 Gemini CLI 進行互動了。

您可以直接在終端機中透過自然語言下指令。例如,嘗試問一個問題:

```bash
gemini "請為我解釋什麼是 API"

您也可以讓它協助處理本地檔案,例如,請它讀取一個檔案並進行總結:

gemini "請幫我總結 `C:\Users\USER\index.txt` 這個檔案的內容"

步驟四:探索更多功能

Gemini CLI 的功能遠不止於此。

  • 它內建了檔案操作、網路搜尋、執行 shell 命令等多種工具。
  • 擁有高達 1M token 的上下文視窗,能夠理解非常複雜的程式碼庫。
  • 嘗試讓它幫您撰寫程式碼、尋找錯誤 (debug)、或是產生程式碼註解與文件。

結論

恭喜您!您已經成功安裝並學會了 Gemini CLI 的基本使用。

在這篇文章中,我們學習了如何:

  • 透過 npx 安裝 Gemini CLI。
  • 完成 Google 帳號認證。
  • 下達基本指令並與之互動。

希望這篇教學對您有幫助!現在您可以在您的開發流程中盡情使用這個強大的工具了。


Happy Coding!

# Gemini.md

終端機輸入指令 **~/.gemini/GEMINI.md**

或者 **GEMINI.md**

預設:

```markdown
# GEMINI Analysis: User Home Directory

## Directory Overview

This directory is the user's home directory (`C:\Users\USER`). It is not a single, self-contained code project but rather a central location for the user's files, development projects, and application configurations.

The user, "charley," is a developer who uses tools like `git`, Docker, and the Cursor code editor.

## Key Files & Directories

This directory contains configuration files for various development tools and subdirectories for different projects.

### Configuration:

*   **`.gitconfig`**: Configures Git with the username "charley".
*   **`.docker`**: Contains Docker configuration files.
*   **`.gradle`**: Contains configuration and cache for the Gradle build tool.
*   **`.m2`**: Local Maven repository.
*   **`.npm`**: Likely contains Node.js package manager configuration and cache.
*   **`.vscode`, `.cursor`**: Configuration for Visual Studio Code and the Cursor editor.

### Project Directories:

The user appears to work on a variety of software projects, as indicated by the following directories:

*   **`c_code`**: Contains C language projects.
*   **`arduino_code`**: Contains projects for the Arduino platform.
*   **`source`**: A general-purpose directory for source code.
*   **`0710Git_excercise`**: A Git exercise repository.

### Other Notable Directories:

*   **`Documents`**, **`Downloads`**, **`Desktop`**: Standard user directories for personal files.
*   **`OneDrive`**: Microsoft OneDrive synchronization directory.

## Usage

This directory serves as the root for the user's development activities. When interacting with me, you can assume that I have access to the files and tools within this directory. You can ask me to:

*   Work with files in any of the project directories (`c_code`, `arduino_code`, etc.).
*   Use `git` to interact with repositories.
*   Leverage configuration from the various dotfiles (`.gitconfig`, `.docker`, etc.).

GEMINI.md 檔案採用 Markdown 格式,可以有好幾個,並以階層式方式載入,由多個位置的內容合併而成。

載入順序如下:

  1. 全域環境:~/.gemini/GEMINI.md (適用於所有專案的指示)。
  2. **專案/祖先內容:**CLI 會從目前目錄向上搜尋至專案根目錄,尋找 GEMINI.md 檔案。
  3. **子目錄環境:**CLI 也會掃描子目錄中的 GEMINI.md 檔案,以便提供元件專屬的指令。

可以使用 /memory show 查看傳送至模型的最終合併內容。


上一篇
結合 Gemini CLI 與 Spec-kit 利用 SDD 開發安卓應用(含基礎教學)
系列文
Android 不會只更新 UI ! 用 Vibe Coding ? 加速打造 Al-native App27
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言