2025-06-09 19:58:24 +00:00
# Gemini CLI Execution and Deployment
2025-06-17 22:02:07 -07:00
This document describes how to run Gemini CLI and explains the deployment architecture that Gemini CLI uses.
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
## Running Gemini CLI
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
There are several ways to run Gemini CLI. The option you choose depends on how you intend to use Gemini CLI.
2025-06-09 19:58:24 +00:00
---
2025-06-17 22:02:07 -07:00
### 1. Standard installation (Recommended for typical users)
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
This is the recommended way for end-users to install Gemini CLI. It involves downloading the Gemini CLI package from the NPM registry.
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
- **Global install:**
2025-06-09 19:58:24 +00:00
```bash
2025-06-25 05:41:11 -07:00
npm install -g @google/gemini -cli
2025-07-14 18:21:40 +02:00
```
Then, run the CLI from anywhere:
2025-06-09 19:58:24 +00:00
2025-07-14 18:21:40 +02:00
```bash
2025-06-09 19:58:24 +00:00
gemini
```
2025-06-17 22:02:07 -07:00
- **NPX execution:**
2025-07-14 18:21:40 +02:00
2025-06-09 19:58:24 +00:00
```bash
# Execute the latest version from NPM without a global install
2025-06-25 05:41:11 -07:00
npx @google/gemini -cli
2025-06-09 19:58:24 +00:00
```
---
2025-06-17 22:02:07 -07:00
### 2. Running in a sandbox (Docker/Podman)
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
For security and isolation, Gemini CLI can be run inside a container. This is the default way that the CLI executes tools that might have side effects.
2025-06-09 19:58:24 +00:00
- **Directly from the Registry:**
You can run the published sandbox image directly. This is useful for environments where you only have Docker and want to run the CLI.
```bash
# Run the published sandbox image
2025-06-25 06:47:27 -07:00
docker run --rm -it us-docker.pkg.dev/gemini-code-dev/gemini-cli/sandbox:0.1.1
2025-06-09 19:58:24 +00:00
```
- **Using the `--sandbox` flag:**
2025-06-17 22:02:07 -07:00
If you have Gemini CLI installed locally (using the standard installation described above), you can instruct it to run inside the sandbox container.
2025-06-09 19:58:24 +00:00
```bash
2025-07-05 10:05:56 +08:00
gemini --sandbox -y -p "your prompt here"
2025-06-09 19:58:24 +00:00
```
---
2025-06-17 22:02:07 -07:00
### 3. Running from source (Recommended for Gemini CLI contributors)
2025-06-09 19:58:24 +00:00
Contributors to the project will want to run the CLI directly from the source code.
- **Development Mode:**
2025-06-17 22:02:07 -07:00
This method provides hot-reloading and is useful for active development.
2025-06-09 19:58:24 +00:00
```bash
# From the root of the repository
npm run start
```
2025-06-17 22:02:07 -07:00
- **Production-like mode (Linked package):**
This method simulates a global installation by linking your local package. It's useful for testing a local build in a production workflow.
2025-06-09 19:58:24 +00:00
```bash
# Link the local cli package to your global node_modules
npm link packages/cli
# Now you can run your local version using the `gemini` command
gemini
```
---
2025-06-17 22:02:07 -07:00
### 4. Running the latest Gemini CLI commit from GitHub
2025-06-09 19:58:24 +00:00
2025-06-25 03:53:03 +00:00
You can run the most recently committed version of Gemini CLI directly from the GitHub repository. This is useful for testing features still in development.
2025-06-09 19:58:24 +00:00
```bash
# Execute the CLI directly from the main branch on GitHub
2025-06-26 03:58:11 +09:00
npx https://github.com/google-gemini/gemini-cli
2025-06-09 19:58:24 +00:00
```
2025-06-17 22:02:07 -07:00
## Deployment architecture
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
The execution methods described above are made possible by the following architectural components and processes:
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
**NPM packages**
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
Gemini CLI project is a monorepo that publishes two core packages to the NPM registry:
2025-06-09 19:58:24 +00:00
2025-06-25 05:41:11 -07:00
- `@google/gemini-cli-core` : The backend, handling logic and tool execution.
- `@google/gemini-cli` : The user-facing frontend.
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
These packages are used when performing the standard installation and when running Gemini CLI from the source.
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
**Build and packaging processes**
2025-06-09 19:58:24 +00:00
There are two distinct build processes used, depending on the distribution channel:
2025-06-25 05:41:11 -07:00
- **NPM publication:** For publishing to the NPM registry, the TypeScript source code in `@google/gemini-cli-core` and `@google/gemini-cli` is transpiled into standard JavaScript using the TypeScript Compiler (`tsc` ). The resulting `dist/` directory is what gets published in the NPM package. This is a standard approach for TypeScript libraries.
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
- **GitHub `npx` execution:** When running the latest version of Gemini CLI directly from GitHub, a different process is triggered by the `prepare` script in `package.json` . This script uses `esbuild` to bundle the entire application and its dependencies into a single, self-contained JavaScript file. This bundle is created on-the-fly on the user's machine and is not checked into the repository.
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
**Docker sandbox image**
2025-06-09 19:58:24 +00:00
2025-07-07 16:36:51 -07:00
The Docker-based execution method is supported by the `gemini-cli-sandbox` container image. This image is published to a container registry and contains a pre-installed, global version of Gemini CLI.
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
## Release process
2025-06-09 19:58:24 +00:00
2025-07-07 16:36:51 -07:00
The release process is automated through GitHub Actions. The release workflow performs the following actions:
2025-06-09 19:58:24 +00:00
2025-06-17 22:02:07 -07:00
1. Build the NPM packages using `tsc` .
2025-07-07 16:36:51 -07:00
2. Publish the NPM packages to the artifact registry.
3. Create GitHub releases with bundled assets.