安装器内部机制
OpenClaw 提供三个安装脚本,由openclaw.ai 提供。
快速命令
- install.sh
- install-cli.sh
- install.ps1
如果安装成功但在新终端中找不到
openclaw,请参见 Node.js 故障排除。install.sh
流程(install.sh)
1
检测操作系统
支持 macOS 和 Linux(包括 WSL)。如果检测到 macOS,则会在缺少 Homebrew 时安装它。
2
默认确保使用 Node.js 24
检查 Node 版本,并在需要时安装 Node 24(macOS 上使用 Homebrew,Linux apt/dnf/yum 上使用 NodeSource 设置脚本)。为了兼容性,OpenClaw 仍支持 Node 22 LTS,目前为
22.16+。3
确保安装 Git
如果缺少 Git,则安装它。
4
安装 OpenClaw
npm方法(默认):全局 npm 安装git方法:克隆/更新仓库,使用 pnpm 安装依赖,构建,然后将包装器安装到~/.local/bin/openclaw
5
安装后任务
- 在升级和 git 安装时运行
openclaw doctor --non-interactive(尽力而为) - 在适当情况下尝试运行新手引导(有 TTY、未禁用新手引导,并且 bootstrap/配置检查通过)
- 默认设置
SHARP_IGNORE_GLOBAL_LIBVIPS=1
源码检出检测
如果在 OpenClaw 检出目录中运行(package.json + pnpm-workspace.yaml),脚本会提供:
- 使用检出目录(
git),或 - 使用全局安装(
npm)
npm 并发出警告。
对于无效的方法选择或无效的 --install-method 值,脚本会以退出码 2 退出。
示例(install.sh)
- 默认
- 跳过新手引导
- Git 安装
- 通过 npm 安装 GitHub main
- 试运行
标志参考
标志参考
环境变量参考
环境变量参考
install-cli.sh
适用于你希望所有内容都放在本地前缀(默认
~/.openclaw)下,并且不依赖系统 Node 的环境。流程(install-cli.sh)
1
安装本地 Node 运行时
将固定的受支持 Node tarball(当前默认
22.22.0)下载到 <prefix>/tools/node-v<version>,并验证 SHA-256。2
确保安装 Git
如果缺少 Git,则尝试在 Linux 上通过 apt/dnf/yum 安装,或在 macOS 上通过 Homebrew 安装。
3
在前缀下安装 OpenClaw
使用
--prefix <prefix> 通过 npm 安装,然后将包装器写入 <prefix>/bin/openclaw。示例(install-cli.sh)
- 默认
- 自定义前缀 + 版本
- 自动化 JSON 输出
- 运行新手引导
标志参考
标志参考
环境变量参考
环境变量参考
install.ps1
流程(install.ps1)
1
确保 PowerShell + Windows 环境
需要 PowerShell 5+。
2
默认确保使用 Node.js 24
如果缺少,则依次尝试通过 winget、Chocolatey、Scoop 安装。为了兼容性,Node 22 LTS(当前为
22.16+)仍然受支持。3
安装 OpenClaw
npm方法(默认):使用所选-Tag进行全局 npm 安装git方法:克隆/更新仓库,使用 pnpm 安装/构建,并将包装器安装到%USERPROFILE%\.local\bin\openclaw.cmd
4
安装后任务
在可能情况下将所需 bin 目录添加到用户 PATH,然后在升级和 git 安装时运行
openclaw doctor --non-interactive(尽力而为)。示例(install.ps1)
- 默认
- Git 安装
- 通过 npm 安装 GitHub main
- 自定义 git 目录
- 试运行
- 调试跟踪
标志参考
标志参考
环境变量参考
环境变量参考
如果使用
-InstallMethod git 且缺少 Git,脚本会退出并打印 Git for Windows 链接。CI 和自动化
使用非交互式标志/环境变量以实现可预测的运行。- install.sh(非交互式 npm)
- install.sh(非交互式 git)
- install-cli.sh(JSON)
- install.ps1(跳过新手引导)
故障排除
为什么需要 Git?
为什么需要 Git?
git 安装方法需要 Git。对于 npm 安装,仍然会检查/安装 Git,以避免当依赖使用 git URL 时出现 spawn git ENOENT 失败。为什么 npm 在 Linux 上会遇到 EACCES?
为什么 npm 在 Linux 上会遇到 EACCES?
某些 Linux 设置会将 npm 全局前缀指向 root 拥有的路径。
install.sh 可以将前缀切换到 ~/.npm-global,并将 PATH 导出追加到 shell rc 文件中(如果这些文件存在)。Windows:“npm error spawn git / ENOENT”
Windows:“npm error spawn git / ENOENT”
安装 Git for Windows,重新打开 PowerShell,然后重新运行安装器。
Windows:“openclaw is not recognized”
Windows:“openclaw is not recognized”
运行
npm config get prefix,并将该目录添加到你的用户 PATH(Windows 上不需要 \bin 后缀),然后重新打开 PowerShell。Windows:如何获取详细安装器输出
Windows:如何获取详细安装器输出
install.ps1 目前没有提供 -Verbose 开关。
对于脚本级诊断,请使用 PowerShell 跟踪:安装后找不到 openclaw
安装后找不到 openclaw
通常是 PATH 问题。请参见 Node.js 故障排除。