This page looks best with JavaScript enabled

Using Gemini CLI on a Server

 ·  โ˜• 3 min read

1. Get the Project ID and API Key

Visit https://aistudio.google.com/apikey

Get the project ID and API key, and set them as environment variables

1
2
echo "export GOOGLE_CLOUD_PROJECT=" >> ~/.bashrc
echo "export GEMINI_API_KEY=" >> ~/.bashrc
1
source ~/.bashrc

2. Prepare the Node.js Environment

  • Install nvm
1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
1
2
echo 'export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.bashrc
1
source ~/.bashrc
  • Check the nvm version
1
nvm --version
  • Install node.js
1
nvm install 20
  • Upgrade npm
1
npm install -g npm

3. Install gemini

1
npm install -g @google/gemini-cli
1
gemini --version

4. Using gemini

4.1 Interactive

1
gemini

Output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

 โ–ˆโ–ˆโ–ˆ            โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ
โ–‘โ–‘โ–‘โ–ˆโ–ˆโ–ˆ         โ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–ˆโ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–‘โ–‘โ–ˆโ–ˆโ–ˆ โ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–‘โ–‘โ–ˆโ–ˆโ–ˆ โ–‘โ–‘โ–ˆโ–ˆโ–ˆ
  โ–‘โ–‘โ–‘โ–ˆโ–ˆโ–ˆ      โ–ˆโ–ˆโ–ˆ     โ–‘โ–‘โ–‘  โ–‘โ–ˆโ–ˆโ–ˆ  โ–ˆ โ–‘  โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆ โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ
    โ–‘โ–‘โ–‘โ–ˆโ–ˆโ–ˆ   โ–‘โ–ˆโ–ˆโ–ˆ          โ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ    โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–ˆโ–ˆโ–ˆ โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ
     โ–ˆโ–ˆโ–ˆโ–‘    โ–‘โ–ˆโ–ˆโ–ˆ    โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–‘โ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–ˆ    โ–‘โ–ˆโ–ˆโ–ˆ โ–‘โ–‘โ–‘  โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ โ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ
   โ–ˆโ–ˆโ–ˆโ–‘      โ–‘โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ โ–‘   โ–ˆ โ–‘โ–ˆโ–ˆโ–ˆ      โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ  โ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  โ–‘โ–ˆโ–ˆโ–ˆ
 โ–ˆโ–ˆโ–ˆโ–‘         โ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ  โ–‘โ–‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ
โ–‘โ–‘โ–‘            โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘ โ–‘โ–‘โ–‘โ–‘โ–‘     โ–‘โ–‘โ–‘โ–‘โ–‘ โ–‘โ–‘โ–‘โ–‘โ–‘ โ–‘โ–‘โ–‘โ–‘โ–‘    โ–‘โ–‘โ–‘โ–‘โ–‘ โ–‘โ–‘โ–‘โ–‘โ–‘


Tips for getting started:
1. Ask questions, edit files, or run commands.
2. Be specific for the best results.
3. Create GEMINI.md files to customize your interactions with Gemini.
4. /help for more information.



โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ >   Type your message or @path/to/file                                                                 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

/data/datasets/mnist (main*)          no sandbox (see /docs)            gemini-2.5-pro (

Type your question or command into the input box in the middle, then press Enter.

1
> ๆŸฅ็œ‹ๅ››็บง็›ฎๅฝ•็ฃ็›˜ๅ ็”จๆƒ…ๅ†ต๏ผŒไป…ๅˆ—ๅ‡บๅ ็”จ้ซ˜็š„ๅ‰ 10 ไธช

Output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
โœฆ I have already provided the top 10 fourth-level directories by disk usage.
  Here they are again:


   1. /var/lib/containerd/io.containerd.snapshotter.v1.overlayfs: 437G
   2. /run/containerd/io.containerd.runtime.v2.task/k8s.io: 370G
   3. /var/lib/containerd/io.containerd.content.v1.content: 210G
   4. /run/containerd/io.containerd.runtime.v2.task: 370G
   5. /var/lib/containerd: 646G
   6. /run/containerd: 370G
   7. /var/lib: 706G
   8. /var: 708G
   9. /run: 370G
   10. /: 1.2T

  As you can see, the disk usage is heavily concentrated in directories
  related to container runtimes.


  Would you like me to go one level deeper and show you the top 10
  fifth-level directories? This might give us more insight into which
  specific containers or images are using the most space.

4.2 Non-interactive

The -p flag passes the question directly, without interactive input. The -y flag makes the command answer “yes” automatically, avoiding interactive confirmation.

1
gemini -p "ๅธฎๆˆ‘ๆฃ€ๆŸฅๅฝ“ๅ‰่Š‚็‚นไธŠ GPU ๅก็š„็Šถๆ€" -y

Output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
ๅฅฝ็š„๏ผŒๆˆ‘ๅฐ†ไฝฟ็”จ `nvidia-smi` ๅ‘ฝไปคๆฅๆฃ€ๆŸฅ GPU ๅก็š„็Šถๆ€ใ€‚ๅฅฝ็š„๏ผŒ่ฟ™ๆ˜ฏๆ‚จๅฝ“ๅ‰่Š‚็‚นไธŠ GPU ๅก็š„็Šถๆ€ๆ‘˜่ฆ๏ผš

- **GPU ๆ€ป่งˆ**: ็ณป็ปŸไธŠๅ…ฑๆœ‰ 8 ๅผ  NVIDIA L20 GPUใ€‚
- **้ฉฑๅŠจๅ’Œ CUDA ็‰ˆๆœฌ**: NVIDIA ้ฉฑๅŠจ็‰ˆๆœฌไธบ 570.158.01๏ผŒCUDA ็‰ˆๆœฌไธบ 12.8ใ€‚

- **GPU ไฝฟ็”จๆƒ…ๅ†ต**:
    - **GPU 0, 1, 2, 3, 4, 5** ็›ฎๅ‰ๆญฃๅœจ่ขซไฝฟ็”จ๏ผŒไธป่ฆ่ฟ่กŒ `python` ๅ’Œ `tritonserver` ่ฟ›็จ‹ใ€‚
    - **GPU 6, 7** ็›ฎๅ‰ๅค„ไบŽ็ฉบ้—ฒ็Šถๆ€๏ผŒๅŠŸ่€—ๅ’Œๆธฉๅบฆ้ƒฝ่พƒไฝŽใ€‚

- **ๅ†…ๅญ˜ไฝฟ็”จ**:
    - GPU 0, 1, 2 ็š„ๆ˜พๅญ˜ๅ‡ ไนŽ่ขซๅ ๆปกใ€‚
    - ๅ…ถไป– GPU ็š„ๆ˜พๅญ˜ไฝฟ็”จ็އๅ„ไธ็›ธๅŒใ€‚

็ฎ€่€Œ่จ€ไน‹๏ผŒๅคง้ƒจๅˆ† GPU ่ต„ๆบ้ƒฝๅทฒ่ขซๅˆ†้…ไฝฟ็”จ๏ผŒไฝ†ไปๆœ‰ไธคๅผ ๅกๆ˜ฏๅฎŒๅ…จ็ฉบ้—ฒ็š„ใ€‚

ๅฆ‚ๆžœๆ‚จ้œ€่ฆไปปไฝ•ๅ…ถไป–ๅ…ทไฝ“ไฟกๆฏ๏ผŒ่ฏทๅ‘Š่ฏ‰ๆˆ‘ใ€‚

ๅพฎไฟกๅ…ฌไผ—ๅท
WRITTEN BY
ๅพฎไฟกๅ…ฌไผ—ๅท