Skip to content

OpenClaw 提供 macOS/Linux/WSL 和 Windows 三种安装脚本。install.sh 适合交互式安装,自动管理 Node.js 24、Git 及依赖;install-cli.sh 将 Node + OpenClaw 安装到 ~/.openclaw 前缀,无需 root;install.ps1 通过 winget/Chocolatey/Scoop 或便携版 Node 安装。所有脚本都支持 npm 或 git 安装方式,并可跳过引导流程用于 CI 自动化。安装后若出现 PATH 问题或 Git 相关报错,请先检查环境变量并参考 Node.js 故障排查页。

OpenClaw 安装脚本说明与配置方法

OpenClaw 在 openclaw.ai 提供三个安装脚本,分别覆盖不同平台和场景。

脚本平台功能说明
install.shmacOS / Linux / WSL按需安装 Node.js 24,通过 npm(默认)或 git 安装 OpenClaw,可运行交互式引导流程(onboarding)。
install-cli.shmacOS / Linux / WSL将 Node + OpenClaw 安装到本地前缀(默认 ~/.openclaw),不依赖系统 Node,支持 npm 或 git。
install.ps1Windows (PowerShell)按需安装 Node.js 24,通过 npm 或 git 安装 OpenClaw,可运行引导流程。

快速命令

install.sh:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash
bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --help

install-cli.sh:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash
bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash -s -- --help

install.ps1:

powershell
iwr -useb https://openclaw.ai/install.ps1 | iex
powershell
& ([scriptblock]::Create((iwr -useb https://openclaw.ai/install.ps1))) -Tag beta -NoOnboard -DryRun

注意: 如果安装成功但新终端找不到 openclaw,请参见 Node.js 故障排查


install.sh:macOS/Linux/WSL 交互式安装

推荐场景: 大多数用户首次安装,需要自动处理 Homebrew、Node.js、Git 和入门引导。

执行流程(install.sh)

  1. 检测操作系统:支持 macOS 和 Linux(含 WSL)。macOS 缺少 Homebrew 时自动安装。
  2. 确保 Node.js 24 作为默认版本:检查当前 Node 版本,若低于 24 则通过 Homebrew(macOS)或 NodeSource 脚本(Linux apt/dnf/yum)安装 Node 24。OpenClaw 仍兼容 Node 22 LTS 的 22.19+
  3. 确保 Git:缺失时自动安装。
  4. 安装 OpenClaw
    • npm 方式(默认):全局 npm install。
    • git 方式:克隆/更新仓库,使用 pnpm 安装依赖并构建,包装脚本写入 ~/.local/bin/openclaw
  5. 安装后处理
    • 尽力刷新已加载的 gateway 服务(运行 openclaw gateway install --force 后重启)。
    • 升级或 git 安装时运行 openclaw doctor --non-interactive(尽力而为)。
    • 有 TTY、未禁用引导且 bootstrap/config 检查通过时启动引导。
    • 默认设置 SHARP_IGNORE_GLOBAL_LIBVIPS=1

源码目录检测

如果当前目录是 OpenClaw 源码(含 package.jsonpnpm-workspace.yaml),脚本会询问:

  • 使用当前源码(git 方式)
  • 还是全局安装(npm 方式)

若没有 TTY 且未指定安装方式,默认采用 npm 并给出警告。无效的安装方式选择或 --install-method 值会导致脚本以退出码 2 结束。

典型用法(install.sh)

默认安装(交互式):

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash

跳过引导:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --no-onboard

Git 方式安装:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --install-method git

使用 GitHub main 分支:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --install-method git --version main

演练模式(仅打印,不执行):

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --dry-run

参数说明:

参数说明
--install-method npm|git安装方式,默认 npm。别名 --method
--npmnpm 方式快捷键
--gitgit 方式快捷键,别名 --github
--version <version|dist-tag|spec>npm 版本、dist-tag 或包规范,默认 latest
--beta使用 beta 标签(若存在),否则回退 latest
--git-dir &lt;path&gt;git 检出目录,默认 ~/openclaw。别名 --dir
--no-git-update跳过已有检出的 git pull
--no-prompt禁用所有交互提示
--no-onboard跳过引导流程
--onboard启用引导流程
--dry-run仅打印将要执行的操作
--verbose开启调试输出(set -x,npm notice 级日志)
--help显示帮助

环境变量:

变量说明
OPENCLAW_INSTALL_METHOD=git|npm安装方式
OPENCLAW_VERSION=latest|next|main|&lt;semver&gt;|&lt;spec&gt;npm 版本、dist-tag 或包规范
OPENCLAW_BETA=0|1是否使用 beta 标签
OPENCLAW_GIT_DIR=&lt;path&gt;git 检出目录
OPENCLAW_GIT_UPDATE=0|1是否执行 git 更新
OPENCLAW_NO_PROMPT=1禁用提示
OPENCLAW_NO_ONBOARD=1跳过引导
OPENCLAW_DRY_RUN=1演练模式
OPENCLAW_VERBOSE=1调试模式
OPENCLAW_NPM_LOGLEVEL=error|warn|noticenpm 日志级别
SHARP_IGNORE_GLOBAL_LIBVIPS=0|1控制 sharp/libvips,默认 1

install-cli.sh:本地前缀安装(无系统 Node 依赖)

适用场景: 希望完全隔离系统环境,将 OpenClaw 和 Node 安装到指定前缀(默认 ~/.openclaw),不要求 root 权限。

执行流程(install-cli.sh)

  1. 安装本地 Node 运行时:下载脚本内置固定版本的 Node LTS tarball(当前版本独立维护),解压到 &lt;prefix&gt;/tools/node-v&lt;version&gt;,并校验 SHA-256。
  2. 确保 Git:缺失时通过 apt/dnf/yum(Linux)或 Homebrew(macOS)安装。
  3. 在前缀下安装 OpenClaw
    • npm 方式(默认):使用 npm --prefix 安装,包装脚本写入 &lt;prefix&gt;/bin/openclaw
    • git 方式:克隆/更新仓库(默认 ~/openclaw),使用 pnpm 构建,包装脚本同样写入 &lt;prefix&gt;/bin/openclaw
  4. 刷新已加载的 gateway 服务:若同一前缀下已有 gateway 服务,则运行 openclaw gateway install --forceopenclaw gateway restart,并尽力检测 gateway 健康状况。

典型用法(install-cli.sh)

默认安装:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash

自定义前缀和版本:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash -s -- --prefix /opt/openclaw --version latest

Git 方式安装:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash -s -- --install-method git --git-dir ~/openclaw

自动化 JSON 输出:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash -s -- --json --prefix /opt/openclaw

安装后运行引导:

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash -s -- --onboard

参数说明:

参数说明
--prefix &lt;path&gt;安装前缀,默认 ~/.openclaw
--install-method npm|git安装方式,默认 npm。别名 --method
--npmnpm 快捷键
--git, --githubgit 快捷键
--git-dir &lt;path&gt;git 检出目录,默认 ~/openclaw。别名 --dir
--version &lt;ver&gt;OpenClaw 版本或 dist-tag,默认 latest
--node-version &lt;ver&gt;Node 版本,默认 22.22.0
--json输出 NDJSON 事件(便于 CI 解析)
--onboard安装后运行 openclaw onboard
--no-onboard跳过引导(默认)
--set-npm-prefixLinux 上强制将 npm 前缀设为 ~/.npm-global(当前前缀不可写时有用)
--help显示帮助

环境变量:

变量说明
OPENCLAW_PREFIX=&lt;path&gt;安装前缀
OPENCLAW_INSTALL_METHOD=git|npm安装方式
OPENCLAW_VERSION=&lt;ver&gt;OpenClaw 版本或 dist-tag
OPENCLAW_NODE_VERSION=&lt;ver&gt;Node 版本
OPENCLAW_GIT_DIR=&lt;path&gt;git 检出目录
OPENCLAW_GIT_UPDATE=0|1是否更新已有 git 检出
OPENCLAW_NO_ONBOARD=1跳过引导
OPENCLAW_NPM_LOGLEVEL=error|warn|noticenpm 日志级别
SHARP_IGNORE_GLOBAL_LIBVIPS=0|1控制 sharp/libvips,默认 1

install.ps1:Windows PowerShell 安装

环境要求: PowerShell 5+。

执行流程(install.ps1)

  1. 确保 PowerShell 环境:必须 5 或更高版本。
  2. 确保 Node.js 24(默认):缺失时依次尝试通过 winget、Chocolatey、Scoop 安装。若均不可用,则下载官方 Node.js Windows zip 到 %LOCALAPPDATA%\OpenClaw\deps\portable-node,并添加到当前进程及用户 PATH。Node 22 LTS(22.19+)仍兼容。
  3. 安装 OpenClaw
    • npm 方式(默认):从可写的临时目录执行全局 npm install(使用 -Tag 参数)。
    • git 方式:克隆/更新仓库,使用 pnpm 构建,包装脚本写入 %USERPROFILE%\.local\bin\openclaw.cmd
  4. 安装后处理
    • 尽可能将所需的 bin 目录添加至用户 PATH。
    • 尽力刷新已加载的 gateway 服务(openclaw gateway install --force 后重启)。
    • 升级或 git 安装时运行 openclaw doctor --non-interactive(尽力而为)。
  5. 失败处理iwr ... | iex 和 scriptblock 安装方式会报告终止错误但不关闭当前 PowerShell 会话。直接 powershell -File / pwsh -File 方式会以非零退出码退出(适合自动化)。

典型用法(install.ps1)

默认安装:

powershell
iwr -useb https://openclaw.ai/install.ps1 | iex

Git 方式安装:

powershell
& ([scriptblock]::Create((iwr -useb https://openclaw.ai/install.ps1))) -InstallMethod git

从 GitHub main 分支安装:

powershell
& ([scriptblock]::Create((iwr -useb https://openclaw.ai/install.ps1))) -InstallMethod git -Tag main

自定义 git 目录:

powershell
& ([scriptblock]::Create((iwr -useb https://openclaw.ai/install.ps1))) -InstallMethod git -GitDir "C:\openclaw"

演练模式:

powershell
& ([scriptblock]::Create((iwr -useb https://openclaw.ai/install.ps1))) -DryRun

调试追踪(install.ps1 暂无专用 -Verbose 参数):

powershell
Set-PSDebug -Trace 1
& ([scriptblock]::Create((iwr -useb https://openclaw.ai/install.ps1))) -NoOnboard
Set-PSDebug -Trace 0

参数说明:

参数说明
-InstallMethod npm|git安装方式,默认 npm
-Tag <tag|version|spec>npm dist-tag、版本或包规范,默认 latest
-GitDir &lt;path&gt;git 检出目录,默认 %USERPROFILE%\openclaw
-NoOnboard跳过引导
-NoGitUpdate跳过 git pull
-DryRun仅打印操作

环境变量:

变量说明
OPENCLAW_INSTALL_METHOD=git|npm安装方式
OPENCLAW_GIT_DIR=&lt;path&gt;git 检出目录
OPENCLAW_NO_ONBOARD=1跳过引导
OPENCLAW_GIT_UPDATE=0禁用 git pull
OPENCLAW_DRY_RUN=1演练模式

注意: 使用 -InstallMethod git 但系统未安装 Git 时,脚本会退出并输出 Git for Windows 下载链接。


CI 和自动化

使用非交互式参数或环境变量确保运行结果可预测。

install.sh(非交互式 npm,跳过引导):

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash -s -- --no-prompt --no-onboard

install.sh(非交互式 git):

bash
OPENCLAW_INSTALL_METHOD=git OPENCLAW_NO_PROMPT=1 \
  curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install.sh | bash

install-cli.sh(JSON 输出,适合 CI 解析):

bash
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash -s -- --json --prefix /opt/openclaw

install.ps1(跳过引导):

powershell
& ([scriptblock]::Create((iwr -useb https://openclaw.ai/install.ps1))) -NoOnboard

常见问题

安装后提示 openclaw: command not found 怎么办?

通常是 PATH 未包含 OpenClaw 可执行文件。运行 openclaw doctor(若已安装)或查看 Node.js 故障排查。Windows 上请检查 %USERPROFILE%\.local\bin 或 npm 全局前缀目录是否在 PATH 中。

Linux 安装时 npm 报 EACCES 错误怎么解决?

这是因为 npm 全局前缀指向 root 拥有的目录。使用 install.sh--set-npm-prefix 参数(或设置环境变量)强制将前缀切换到 ~/.npm-global。脚本会自动修改 shell rc 文件。你也可以手动运行 npm config set prefix ~/.npm-global 然后再运行安装脚本。

Windows 上 Git 安装失败:npm error spawn git / ENOENT

请先安装 Git for Windows 并重启 PowerShell,再重新运行安装脚本。如果使用 -InstallMethod git 但未安装 Git,脚本会退出并显示下载链接。


相关文档