本文档详细介绍 OpenClaw 的环境要求、安装方法和配置步骤。 配套一键部署脚本:
openclaw-deploy.sh、openclaw-deploy-macos-zsh.sh
| 平台 | 支持状态 | 备注 |
|---|---|---|
| macOS | ✅ 完全支持 | macOS 11+ 推荐 |
| Linux | ✅ 完全支持 | Ubuntu 20.04+, Debian 11+, Fedora 35+ |
| Windows | 强烈建议使用 WSL2 |
| 组件 | 最低配置 | 推荐配置 |
|---|---|---|
| CPU | 64位处理器 | 多核处理器 |
| 内存 | 4 GB RAM | 8 GB RAM |
| 磁盘 | 2 GB 可用空间 | 5 GB+ 可用空间 |
| 网络 | 互联网连接 | 稳定的宽带连接 |
- 版本要求: Node.js ≥ 22.12.0
- 推荐版本: Node.js LTS (长期支持版)
检查 Node.js:
node --version
# 应显示 v22.x.x 或更高版本安装 Node.js:
=== "macOS (Homebrew)"
bash brew install node@22 brew link node@22 --force
=== "Ubuntu/Debian"
bash # 使用 NodeSource curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - sudo apt-get install -y nodejs
=== "Fedora/RHEL/CentOS"
bash curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash - sudo dnf install -y nodejs
=== "Arch Linux"
bash sudo pacman -S nodejs npm
=== "使用 NVM (推荐)" ```bash # 安装 NVM curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
# 加载 NVM
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# 安装 Node.js
nvm install --lts
nvm use --lts
nvm alias default lts/*
```
- npm: 随 Node.js 一起安装
- pnpm: 高性能替代方案,节省磁盘空间
- Bun: 超快 JavaScript 运行时和包管理器
安装 pnpm:
curl -fsSL https://get.pnpm.io/install.sh | sh -安装 Bun:
curl -fsSL https://bun.sh/install | bash# macOS
brew install git
# Ubuntu/Debian
sudo apt-get install git
# Fedora
sudo dnf install git| 工具 | 用途 | 安装命令 |
|---|---|---|
| Homebrew | macOS 包管理器 | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| Tailscale | 远程访问 | https://tailscale.com/download |
| Docker | 容器化部署 | https://docs.docker.com/get-docker/ |
专为 macOS Zsh 用户设计,自动处理 PATH 配置问题,无需手动编辑 ~/.zshrc。
一键运行(无需下载):
# macOS 专属脚本 - 使用 Bun 安装(推荐)
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy-macos-zsh.sh) --method bun
# 或使用 pnpm
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy-macos-zsh.sh) --method pnpm
# 或使用 npm(默认)
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy-macos-zsh.sh)特点:
- ✅ 自动检测并配置
~/.zshrc - ✅ 自动添加 Bun/pnpm/npm 全局路径到 PATH
- ✅ 自动重新加载配置
- ✅ 解决 "command not found" 问题
- ✅ 支持 Apple Silicon (M1/M2/M3) 和 Intel Mac
适合所有平台(macOS/Linux/WSL2)。
一键运行(无需下载):
# 通用部署脚本 - 使用 npm 安装(默认)
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh)
# 使用 pnpm 安装
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh) --method pnpm
# 使用 Bun 安装
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh) --method bun脚本选项:
# 查看帮助
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh) --help
# 使用 pnpm 安装
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh) --method pnpm
# 跳过配置向导
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh) --no-onboard
# 使用国内镜像加速
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh) --cn-mirror
# 详细输出
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy.sh) --verbose# macOS / Linux / WSL2
curl -fsSL https://openclaw.ai/install.sh | bash# Windows PowerShell
iwr -useb https://openclaw.ai/install.ps1 | iex# 全局安装
npm install -g openclaw@latest
# 处理 sharp 编译错误 (macOS 用户)
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install -g openclaw@latest
# 运行配置向导
openclaw onboard --install-daemon# 全局安装
pnpm add -g openclaw@latest
# 批准构建脚本
pnpm approve-builds -g
# 运行配置向导
openclaw onboard --install-daemon适合开发者或需要最新功能的用户:
# 克隆仓库
git clone https://github.com/openclaw/openclaw.git
cd openclaw
# 安装依赖
pnpm install
# 构建 UI
pnpm ui:build
# 构建项目
pnpm build
# 链接到全局
pnpm link --global
# 运行配置向导
openclaw onboard --install-daemonBun 是一个快速的 JavaScript 运行时和包管理器,比 npm 快 10-100 倍。
# 安装 Bun (如果尚未安装)
curl -fsSL https://bun.sh/install | bash
# 重新加载 shell
source ~/.bashrc # 或 ~/.zshrc
# 全局安装 OpenClaw
bun install -g openclaw@latest
# 运行配置向导
openclaw onboard --install-daemonBun 的优势:
- 🚀 超快的安装速度
- 📦 自动管理依赖
- 🔋 内置 TypeScript 支持
# 拉取镜像
docker pull openclaw/openclaw:latest
# 运行容器
docker run -d \
--name openclaw \
-p 18789:18789 \
-v ~/.openclaw:/root/.openclaw \
openclaw/openclaw:latest安装完成后,运行配置向导进行初始化:
openclaw onboard --install-daemon向导将引导您完成:
-
身份验证设置
- 配置 AI 模型提供商 (Anthropic, OpenAI 等)
- 设置 API 密钥或 OAuth
-
Gateway 配置
- 设置端口号 (默认: 18789)
- 配置工作目录
- 安装系统服务
-
渠道配置 (可选)
- Telegram
- Slack
- Discord
- 其他消息平台
-
技能配置 (可选)
- 浏览器自动化
- Canvas 可视化
- 节点控制
- 其他扩展功能
# 安装但不运行向导
curl -fsSL https://openclaw.ai/install.sh | bash -s -- --no-onboard
# 稍后手动运行向导
openclaw onboard# 查看 Gateway 状态
openclaw gateway status
# 运行诊断
openclaw doctor# 启动 Gateway
openclaw gateway start
# 停止 Gateway
openclaw gateway stop
# 重启 Gateway
openclaw gateway restart
# 前台运行 (调试用)
openclaw gateway --port 18789 --verbose| 平台 | 服务类型 | 配置文件位置 |
|---|---|---|
| macOS | launchd | ~/Library/LaunchAgents/ai.openclaw.gateway.plist |
| Linux | systemd | ~/.config/systemd/user/openclaw-gateway.service |
原因: npm 全局安装路径不在 PATH 中
解决:
# 添加 npm 全局路径到 shell 配置
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.zshrc # 或 ~/.bashrc
# 重新加载配置
source ~/.zshrc # 或 source ~/.bashrc原因: 本地 libvips 与 sharp 冲突
解决:
# 强制使用预构建二进制文件
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install -g openclaw@latest解决:
# 使用 NVM 升级到最新 LTS
nvm install --lts
nvm use --lts
nvm alias default lts/*检查:
# 检查端口占用
lsof -i :18789
# 检查日志
openclaw gateway --verbose
# 检查配置文件
openclaw doctor解决:
# 修复 npm 权限
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
# 或使用 npx 运行
npx openclaw@latest原因: Bun/pnpm/npm 全局路径未添加到 ~/.zshrc
解决:
# 方案 1: 使用 macOS Zsh 专属脚本 (推荐)
# 自动处理所有 PATH 配置
bash <(curl -fsSL https://raw.githubusercontent.com/xiaoamo22333/OpenClaw_Guide/main/openclaw-deploy-macos-zsh.sh)
# 方案 2: 手动添加路径到 ~/.zshrc
# 如果是 Bun
echo 'export BUN_INSTALL="$HOME/.bun"' >> ~/.zshrc
echo 'export PATH="$BUN_INSTALL/bin:$PATH"' >> ~/.zshrc
# 如果是 pnpm
echo 'export PNPM_HOME="$HOME/Library/pnpm"' >> ~/.zshrc
echo 'export PATH="$PNPM_HOME:$PATH"' >> ~/.zshrc
# 如果是 npm 全局包
export PATH="$(npm prefix -g)/bin:$PATH"
# 重新加载配置
source ~/.zshrc使用 macOS Zsh 专属脚本的优势:
- 自动检测当前 shell 环境
- 自动添加所需 PATH 到
~/.zshrc - 安装后自动重新加载配置
- 无需手动编辑配置文件
| 资源 | 链接 |
|---|---|
| 官方文档 | https://docs.openclaw.ai |
| GitHub | https://github.com/openclaw/openclaw |
| Discord 社区 | https://discord.gg/clawd |
| 问题反馈 | https://github.com/openclaw/openclaw/issues |
| 变量 | 说明 | 示例 |
|---|---|---|
OPENCLAW_HOME |
主目录 | ~/.openclaw |
OPENCLAW_STATE_DIR |
状态目录 | ~/.openclaw/state |
OPENCLAW_CONFIG_PATH |
配置文件路径 | ~/.openclaw/config.json |
OPENCLAW_PORT |
Gateway 端口 | 18789 |
OPENCLAW_LOG_LEVEL |
日志级别 | info, debug, error |
~/.openclaw/config.json:
{
"gateway": {
"port": 18789,
"host": "127.0.0.1"
},
"models": {
"default": "anthropic/claude-opus-4-6",
"fallback": "openai/gpt-4o"
},
"channels": {
"webchat": {
"enabled": true
}
}
}# 检查更新
openclaw update --check
# 更新到最新版本
openclaw update
# 切换到测试频道
openclaw update --channel beta# 停止服务
openclaw gateway stop
# 卸载包 (根据安装方式选择)
npm uninstall -g openclaw
# 或
pnpm remove -g openclaw
# 或
bun uninstall -g openclaw
# 删除配置 (可选)
rm -rf ~/.openclaw
# 删除系统服务 (macOS)
launchctl unload ~/Library/LaunchAgents/ai.openclaw.gateway.plist
rm ~/Library/LaunchAgents/ai.openclaw.gateway.plist
# 删除系统服务 (Linux)
systemctl --user stop openclaw-gateway
rm ~/.config/systemd/user/openclaw-gateway.service-
API 密钥管理
- 不要将 API 密钥提交到版本控制
- 使用环境变量或安全的密钥管理服务
-
DM 安全
- 默认启用配对模式,未知发送者需要批准
- 使用
openclaw pairing approve <channel> <code>批准新用户
-
网络安全
- 使用 Tailscale 或 VPN 保护远程访问
- 避免在公共网络暴露 Gateway 端口
-
定期更新
- 保持 OpenClaw 和依赖项更新
- 运行
openclaw doctor检查安全问题
# 核心命令
openclaw --help # 显示帮助
openclaw dashboard # 打开 Web 控制面板
openclaw gateway status # 查看服务状态
openclaw agent # 启动 AI 对话
openclaw doctor # 运行诊断
# 消息发送
openclaw message send --target +1234567890 --message "Hello"
# 配对管理
openclaw pairing approve telegram ABC123
openclaw pairing reject telegram ABC123
# 配置管理
openclaw config get gateway.port
openclaw config set gateway.port 18888最后更新: 2026-02-22 文档版本: 1.0.0