# 安装 CLI

Tomba CLI（`tomba`）是适用于 macOS、Linux 和 Windows 的单个二进制文件。安装后，按照 [CLI 认证](/cli/authentication)中的说明登录。

## 安装

发布版本提供以下平台的构建：macOS（amd64、arm64）、Linux（386、amd64、armv6、arm64、ppc64）和 Windows（386、amd64、arm64）。

### 安装脚本（macOS 和 Linux）

```bash
curl -sSL https://releases.tomba.io/install.sh | sh
```

该脚本会从 [GitHub Releases](https://github.com/tomba-io/tomba/releases) 下载适用于您平台的最新版本，校验其 SHA-256 校验和，将 `tomba` 安装到 `/usr/local/bin`（如果该目录不可写，则使用 `sudo`），并为 bash、zsh 或 fish 设置补全。如果无法下载校验和文件，或找不到 `sha256sum` 或 `shasum`，脚本会打印一条警告，并在不校验的情况下继续安装；如需自行校验压缩包，请参阅[校验下载文件](#verify-the-download)。

如需固定版本或安装到其他目录，请传入 `--version` 或 `--dir`：

```bash
curl -sSL https://releases.tomba.io/install.sh | sh -s -- --version 1.2.3 --dir "$HOME/.local/bin"
```

### PowerShell（Windows）

```powershell
irm https://releases.tomba.io/install.ps1 | iex
```

该脚本会校验 SHA-256 校验和，将 `tomba.exe` 安装到 `%LOCALAPPDATA%\tomba`，把该文件夹添加到您的用户 `PATH`，并将 PowerShell 补全添加到您的配置文件中。

### Homebrew

```bash
brew install --cask tomba-io/tap/tomba
```

### Scoop（Windows）

```powershell
scoop bucket add tomba https://github.com/tomba-io/scoop-bucket.git
scoop install tomba
```

### Snap（Linux）

```bash
sudo snap install tomba
```

### Linux 软件包

每个版本都包含 `.deb`、`.rpm`、`.apk` 和 Arch Linux（`.pkg.tar.zst`）软件包。例如，在 Debian 或 Ubuntu 上：

```bash
curl -LO https://github.com/tomba-io/tomba/releases/latest/download/tomba_amd64.deb
sudo apt install --no-install-recommends ./tomba_amd64.deb
```

这些软件包依赖 `git` 和 `systemd`，并推荐安装 `golang`；使用 `--no-install-recommends` 可跳过 Go 工具链。它们会安装 shell 补全、man 手册页和一个 systemd 单元 `tomba.service`，该单元以 `www-data` 身份运行 [`tomba serve`](/cli/http)，并设为开机自动启动。如果您不使用本地服务器，请禁用该单元：

```bash
sudo systemctl disable --now tomba
```

### Go

需要 Go 1.25 或更高版本。

```bash
go install github.com/tomba-io/tomba@latest
```

二进制文件会安装到 `$(go env GOPATH)/bin`，该目录必须在您的 `PATH` 中。通过 `go install` 构建的版本会将版本号报告为 `dev`。

## 校验下载文件

每个版本都会发布 `tomba_checksums.txt`，其中包含每个压缩包和软件包的 SHA-256 校验和。如需从压缩包安装并先进行校验：

```bash
VERSION=1.2.3
curl -LO "https://github.com/tomba-io/tomba/releases/download/v${VERSION}/tomba_linux_amd64.tar.gz"
curl -LO "https://github.com/tomba-io/tomba/releases/download/v${VERSION}/tomba_checksums.txt"
sha256sum --ignore-missing -c tomba_checksums.txt
tar -xzf tomba_linux_amd64.tar.gz tomba
sudo install -m 0755 tomba /usr/local/bin/tomba
```

在 macOS 上，使用 `shasum -a 256 --ignore-missing -c tomba_checksums.txt` 以及 `tomba_darwin_arm64` 或 `tomba_darwin_amd64` 压缩包。校验会在压缩包名称旁打印 `OK`；任何其他结果都表示该文件与发布版本不匹配，请不要安装。

## 验证安装

```bash
tomba version
```

```text
tomba 1.2.3
  built:    2026-09-27T14:29:29Z
  commit:   0949b31
  go:       go1.27.1
  os/arch:  linux/amd64
```

`tomba --version` 会以单行形式打印版本号（`tomba version 1.2.3`）。

## Shell 补全

安装脚本、Homebrew 和 Linux 软件包会为您设置补全。如需在当前会话中自行加载：

```bash
# bash (requires the bash-completion package)
source <(tomba completion bash)

# zsh
source <(tomba completion zsh)

# fish
tomba completion fish | source
```

```powershell
tomba completion powershell | Out-String | Invoke-Expression
```

如需在每个新会话中加载补全，请按照 `tomba completion <shell> --help` 为您的 shell 打印的步骤操作。

## 更新

```bash
tomba update
```

`tomba update`（别名 `upgrade`）会在 GitHub 上查找最新版本，下载适用于您平台的压缩包，在校验和文件可用时校验其 SHA-256 校验和，并就地替换 `tomba` 二进制文件。如果二进制文件所在的目录您没有写入权限，该命令会失败并显示 `Cannot rename current binary (may need sudo)`；请使用 `sudo` 运行。

如果您是通过包管理器安装的，请使用同一工具更新，以便它记录版本信息：

| 安装方式 | 更新方式                                      |
| -------------- | ------------------------------------------------ |
| Homebrew       | `brew upgrade --cask tomba`                      |
| Scoop          | `scoop update tomba`                             |
| Snap           | `sudo snap refresh tomba`                        |
| Linux 软件包  | 下载新软件包，并按上述方法安装 |
| Go             | `go install github.com/tomba-io/tomba@latest`    |

## 卸载

| 安装方式           | 卸载方式                                                                                                                             |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| 安装脚本           | `sudo rm /usr/local/bin/tomba`，或从您传给 `--dir` 的目录中删除 `tomba`                                              |
| PowerShell 脚本        | 删除 `%LOCALAPPDATA%\tomba`，将其从您的用户 `PATH` 中移除，并从 PowerShell 配置文件中删除 `tomba.completion.ps1` 这一行 |
| Homebrew                 | `brew uninstall --cask tomba`                                                                                                           |
| Scoop                    | `scoop uninstall tomba`                                                                                                                 |
| Snap                     | `sudo snap remove tomba`                                                                                                                |
| Debian 或 Ubuntu 软件包 | `sudo apt remove tomba`                                                                                                                 |
| RPM 软件包              | `sudo dnf remove tomba`                                                                                                                 |
| Alpine 软件包           | `sudo apk del tomba`                                                                                                                    |
| Arch Linux 软件包       | `sudo pacman -R tomba`                                                                                                                  |
| Go                       | `rm "$(go env GOPATH)/bin/tomba"`                                                                                                       |

CLI 将保存的凭据存放在 `~/.tomba.json` 中，将自定义技能存放在 `~/.tomba/skills/` 中。删除二进制文件不会删除它们；可使用以下命令删除：

```bash
rm -rf ~/.tomba.json ~/.tomba
```
