安装程序内部原理
适用范围
使用本页面当:
- 您想了解
clawd.bot/install.sh - 您需要自动化安装(CI / 无头模式)
- 您想从 GitHub 副本安装
Moltbot 提供两个安装脚本(从 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 -- --helpWindows (PowerShell) 帮助:
& ([scriptblock]::Create((iwr -useb https://clawd.bot/install.ps1))) -?如果安装程序完成但 moltbot 在新终端中未找到,通常是 Node/npm PATH 问题。参见:安装。
install.sh(推荐)
它的作用(概览):
- 检测操作系统(macOS / Linux / WSL)。
- 确保 Node.js 22+(macOS 通过 Homebrew;Linux 通过 NodeSource)。
- 选择安装方法:
npm(默认):npm install -g moltbot@latestgit:克隆/构建源码副本并安装包装脚本
- 在 Linux 上:通过在需要时将 npm 的前缀切换到
~/.npm-global来避免全局 npm 权限错误。 - 如果升级现有安装:运行
moltbot doctor --non-interactive(尽力而为)。 - 对于 git 安装:在安装/更新后运行
moltbot 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 安装"提示
如果您在已经处于 Moltbot 源码副本内时运行安装程序(通过 package.json + pnpm-workspace.yaml 检测),它会提示:
- 更新并使用此副本(
git) - 或迁移到全局 npm 安装(
npm)
在非交互式上下文中(无 TTY / --no-prompt),您必须传递 --install-method git|npm(或设置 MOLTBOT_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安装程序)
此脚本将 moltbot 安装到前缀(默认:~/.moltbot),并在该前缀下还安装专用的 Node 运行时,因此它可以在您不想触摸系统 Node/npm 的机器上工作。
帮助:
curl -fsSL https://clawd.bot/install-cli.sh | bash -s -- --helpinstall.ps1(Windows PowerShell)
它的作用(概览):
- 确保 Node.js 22+(winget/Chocolatey/Scoop 或手动安装)。
- 选择安装方法:
npm(默认):npm install -g moltbot@latestgit:克隆/构建源码副本并安装包装脚本
- 在升级和 git 安装上运行
moltbot doctor --non-interactive(尽力而为)。
示例:
iwr -useb https://clawd.bot/install.ps1 | iexiwr -useb https://clawd.bot/install.ps1 | iex -InstallMethod gitiwr -useb https://clawd.bot/install.ps1 | iex -InstallMethod git -GitDir "C:\\moltbot"环境变量:
MOLTBOT_INSTALL_METHOD=git|npmMOLTBOT_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,然后重新运行安装程序。
- “moltbot” is not recognized:您的 npm 全局 bin 文件夹不在 PATH 上。大多数系统使用
%AppData%\\npm。您也可以运行npm config get prefix并将\\bin添加到 PATH,然后重新打开 PowerShell。