跳到主要内容

安装器内部机制

Clawdbot 提供两个安装脚本(通过 clawd.bot 提供):

  • https://clawd.bot/install.sh — “推荐”安装器(默认使用全局 npm 安装;也可以从 GitHub 检出版安装)
  • https://clawd.bot/install-cli.sh — 对非 root 用户友好的 CLI 安装器(安装到带有自带 Node 的前缀目录下)
  • https://clawd.bot/install.ps1 — Windows PowerShell 安装器(默认 npm;可选 git 安装)

要查看当前的标志位/行为,请运行:

curl -fsSL https://clawd.bot/install.sh | bash -s -- --help

Windows (PowerShell) 帮助:

& ([scriptblock]::Create((iwr -useb https://clawd.bot/install.ps1))) -?

如果安装器运行完成但在新终端中找不到 clawdbot,通常是 Node/npm 的 PATH 问题。请参阅:安装。

install.sh (推荐)​

它所做的工作(高层级):

  • 检测操作系统 (macOS / Linux / WSL)。
  • 确保 Node.js 版本为 22+ (macOS 通过 Homebrew;Linux 通过 NodeSource)。
  • 选择安装方法:
    • npm (默认): npm install -g clawdbot@latest
    • git: 克隆/构建源码检出版并安装包装脚本
  • 在 Linux 上:通过在需要时将 npm 的前缀切换到 ~/.npm-global 来避免全局 npm 权限错误。
  • 如果是升级现有安装:运行 clawdbot doctor --non-interactive(尽力而为)。
  • 对于 git 安装:在安装/更新后运行 clawdbot doctor --non-interactive(尽力而为)。
  • 通过默认设置 SHARP_IGNORE_GLOBAL_LIBVIPS=1 来减轻 sharp 原生安装的陷阱(避免针对系统 libvips 进行构建)。

如果你 希望 sharp 链接到全局安装的 libvips(或者你正在进行调试),请设置:

SHARP_IGNORE_GLOBAL_LIBVIPS=0 curl -fsSL https://clawd.bot/install.sh | bash

可发现性 / “git 安装”提示​

如果你在 已经处于 Clawdbot 源码检出目录中(通过 package.json + pnpm-workspace.yaml 检测)运行安装器,它会提示:

  • 更新并使用此检出版 (git)
  • 或者迁移到全局 npm 安装 (npm)

在非交互式上下文(无 TTY / --no-prompt)中,你必须传递 --install-method git|npm(或设置 CLAWDBOT_INSTALL_METHOD),否则脚本将以退出代码 2 退出。

为什么需要 Git​

对于 --install-method git 路径(克隆 / 拉取),Git 是必需的。

对于 npm 安装,Git 通常 不是必需的,但某些环境最终仍然需要它(例如,当通过 git URL 获取包或依赖项时)。安装器目前会确保 Git 存在,以避免在纯净发行版上出现 spawn git ENOENT 的意外情况。

为什么 npm 在纯净的 Linux 上会遇到 EACCES​

在某些 Linux 设置中(特别是在通过系统包管理器或 NodeSource 安装 Node 之后), npm 的全局前缀指向一个 root 拥有的位置。然后 npm install -g ... 会因 EACCES / mkdir 权限错误而失败。

install.sh 通过将前缀切换到以下位置来减轻这一问题:

  • ~/.npm-global(并在存在时将其添加到 ~/.bashrc / ~/.zshrc 的 PATH 中)

install-cli.sh (非 root CLI 安装器)​

此脚本将 clawdbot 安装到一个前缀目录下(默认:~/.clawdbot),并在该目录下安装专用的 Node 运行时,因此它可以在你不想触动系统 Node/npm 的机器上工作。

帮助:

curl -fsSL https://clawd.bot/install-cli.sh | bash -s -- --help

install.ps1 (Windows PowerShell)​

它所做的工作(高层级):

  • 确保 Node.js 版本为 22+ (winget/Chocolatey/Scoop 或手动安装)。
  • 选择安装方法:
    • npm (默认): npm install -g clawdbot@latest
    • git: 克隆/构建源码检出版并安装包装脚本
  • 在升级和 git 安装时运行 clawdbot doctor --non-interactive(尽力而为)。

示例:

iwr -useb https://clawd.bot/install.ps1 | iex
iwr -useb https://clawd.bot/install.ps1 | iex -InstallMethod git
iwr -useb https://clawd.bot/install.ps1 | iex -InstallMethod git -GitDir "C:\\clawdbot"

环境变量:

  • CLAWDBOT_INSTALL_METHOD=git|npm
  • CLAWDBOT_GIT_DIR=...

Git 要求:

如果你选择 -InstallMethod git 且缺少 Git,安装器将打印 Git for Windows 的链接 (https://git-scm.com/download/win) 并退出。

常见的 Windows 问题:

  • npm error spawn git / ENOENT: 安装 Git for Windows 并重新打开 PowerShell,然后重新运行安装器。
  • "clawdbot" 未被识别: 你的 npm 全局 bin 文件夹不在 PATH 中。大多数系统使用 %AppData%\\npm。你也可以运行 npm config get prefix 并在 PATH 中添加 \bin,然后重新打开 PowerShell。