OpenClaw 安装
选择适合你的工作流程
8-10 分钟
入门
定制策略
本指南帮助你根据使用模式选择最合适的 OpenClaw 配置。不同的工作流程适合不同的场景:
- macOS 用户:使用 OpenClaw macOS 应用获得稳定体验
- 开发者/高级用户:在终端中运行 Gateway 获得最新功能
- Linux 用户:使用 systemd 守护进程实现持久化运行
稳定工作流程(macOS 应用)
适合大多数 macOS 用户,提供图形界面和自动更新功能。
# 安装 OpenClaw macOS 应用
brew install --cask openclaw凭证存储位置
- • macOS 钥匙串:
~/Library/Keychains/login.keychain-db - • 配置文件:
~/.openclaw/openclaw.json
优势
- ✓ 自动后台运行
- ✓ 图形界面管理
- ✓ 自动更新
- ✓ 系统通知集成
前沿工作流程(终端 Gateway)
适合开发者和高级用户,获得最新功能和完全控制。
# 安装并运行 Gateway
# {isZh ? '使用 npm 安装' : 'Install with npm'}
npm install -g @openclaw/gateway
# {isZh ? '或使用 curl 快速安装' : 'Or quick install with curl'}
curl -fsSL https://get.openclaw.ai | sh
# {isZh ? '启动 Gateway' : 'Start Gateway'}
openclaw gateway start注意事项
- • 每次系统重启后需要手动启动
- • 使用 tmux 或 screen 保持会话持久化
- • 配置文件位置不变
优势
- ✓ 访问最新功能
- ✓ 完全控制配置
- ✓ 适合开发和调试
- ✓ 可以查看详细日志
常见陷阱
1. 凭证权限问题
确保 ~/.openclaw 目录的权限正确。不正确的权限会导致凭证无法读取。
chmod 700 ~/.openclaw2. 端口冲突
默认 Gateway 端口是 18789。如果被占用,需要在配置中修改。
openclaw configure --section gateway --key port --value 187903. API 密钥环境变量
确保在 shell 配置文件(~/.zshrc 或 ~/.bashrc)中设置环境变量。
export ANTHROPIC_API_KEY="sk-ant-..."4. Node.js 版本
OpenClaw 需要 Node.js 22 或更高版本。使用 nvm 可以轻松管理版本。
凭证存储位置
macOS
Keychain: ~/Library/Keychains/login.keychain-db
钥匙串自动加密存储
Linux
Config: ~/.openclaw/openclaw.json
JSON 文件存储,建议设置适当权限
Windows
Config: %USERPROFILE%\.openclaw\openclaw.json
WSL2 环境下使用 Linux 路径
更新策略
macOS 应用
自动更新,无需手动操作
brew upgrade --cask openclaw可选:手动更新到最新版本
终端 Gateway
使用 npm 或安装脚本更新
npm update -g @openclaw/gateway或重新运行安装脚本
Linux systemd 设置
使用 systemd 实现 OpenClaw Gateway 的持久化运行和自动启动。
# 创建 systemd user service
# {isZh ? '服务文件位置' : 'Service file location'}
~/.config/systemd/user/openclaw.service
# {isZh ? '启用并启动服务' : 'Enable and start service'}
systemctl --user enable openclaw.service
systemctl --user start openclaw.service
# {isZh ? '启用 lingering 以保持登录后运行' : 'Enable lingering to run after logout'}
loginctl enable-linger $USER服务文件示例
[Unit]
Description=OpenClaw Gateway
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/openclaw gateway start
Restart=always
RestartSec=10
[Install]
WantedBy=default.target管理命令
systemctl --user status openclaw- 查看状态systemctl --user stop openclaw- 停止服务systemctl --user restart openclaw- 重启服务journalctl --user -u openclaw -f- 查看日志