Windows 安装(WSL2)
强烈建议使用 WSL2,而不是原生 Windows。WSL2 提供完整的 Linux 环境,兼容性更好。
第一步:安装 WSL2
打开 PowerShell(管理员):
# 安装 WSL2 + Ubuntu
wsl --install
# 或者指定发行版
wsl --list --online
wsl --install -d Ubuntu-24.04
安装完成后重启电脑。
第二步:启用 systemd
在 WSL 终端中执行:
# 创建 wsl.conf
sudo tee /etc/wsl.conf >/dev/null <<'EOF'
[boot]
systemd=true
EOF
然后在 PowerShell 中重启 WSL:
wsl --shutdown
重新打开 Ubuntu 终端,验证 systemd:
systemctl --user status
第三步:安装 OpenClaw
在 WSL 终端中执行:
# 安装 Node.js 22
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
# 安装 OpenClaw
curl -fsSL https://openclaw.ai/install.sh | bash
# 运行新手引导
openclaw onboard --install-daemon
第四步:设置开机自启(可选)
如果你希望 Windows 启动时自动运行 Gateway:
# 在 PowerShell(管理员)中执行
schtasks /create /tn "WSL Boot" /tr "wsl.exe -d Ubuntu --exec /bin/true" /sc onstart /ru SYSTEM
把 Ubuntu 替换为你的发行版名称(wsl --list --verbose 查看)
第五步:从局域网访问(可选)
WSL 有独立的虚拟网络,如果需要从局域网其他设备访问:
# PowerShell 管理员
$Distro = "Ubuntu-24.04"
$ListenPort = 18789
$TargetPort = 18789
# 获取 WSL IP
$WslIp = (wsl -d $Distro -- hostname -I).Trim().Split(" ")[0]
# 设置端口转发
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$ListenPort connectaddress=$WslIp connectport=$TargetPort
# 添加防火墙规则
New-NetFirewallRule -DisplayName "OpenClaw Gateway" -Direction Inbound -Protocol TCP -LocalPort $ListenPort -Action Allow
配置与启动
配置文件位置
| 文件 | 路径 | 说明 |
|---|---|---|
| 主配置 | ~/.openclaw/openclaw.json | JSON5 格式,支持注释 |
| 工作目录 | ~/.openclaw/workspace/ | 记忆、技能、提示词 |
| 凭证 | ~/.openclaw/credentials/ | 各渠道的认证信息 |
最小配置示例
// ~/.openclaw/openclaw.json
{
// 模型配置(引导会自动生成)
agents: {
defaults: {
workspace: "~/.openclaw/workspace",
},
},
// 渠道配置
channels: {
telegram: {
enabled: true,
botToken: "YOUR_BOT_TOKEN",
dmPolicy: "pairing", // 需要配对才能对话
},
},
}
常用命令
# 查看状态
openclaw status
# 启动 Gateway(前台)
openclaw gateway
# 安装/管理后台服务
openclaw gateway install
openclaw gateway status
openclaw gateway stop
openclaw gateway restart
# 打开 Web 控制台
openclaw dashboard
# 重新配置
openclaw configure
# 诊断问题
openclaw doctor
# 查看日志
openclaw logs --follow
环境变量
| 变量 | 说明 |
|---|---|
| OPENCLAW_HOME | 主目录 |
| OPENCLAW_STATE_DIR | 状态目录 |
| OPENCLAW_CONFIG_PATH | 配置文件路径 |
连接聊天渠道
Telegram(推荐入门)
创建 Bot:在 Telegram 搜索 @BotFather,发送 /newbot
获取 Token:BotFather 会返回类似 123456789:ABCdefGHI… 的 token
配置 OpenClaw:
{
channels: {
telegram: {
enabled: true,
botToken: "123456789:ABCdefGHI...",
dmPolicy: "pairing",
},
},
}
启动 Gateway:openclaw gateway
配对你的账号:
# 给你的 Bot 发一条消息
# 然后在终端查看配对码
openclaw pairing list telegram
# 批准配对
openclaw pairing approve telegram <CODE>
Discord
在 Discord Developer Portal 创建应用
创建 Bot 并获取 Token
启用必要的 Intents(Message Content、Server Members)
配置:
{
channels: {
discord: {
enabled: true,
token: "YOUR_BOT_TOKEN",
groupPolicy: "allowlist",
guilds: {
"YOUR_GUILD_ID": { requireMention: false },
},
},
},
}
# 扫码登录
openclaw channels login --channel whatsapp
# 查看状态
openclaw channels status
访问控制策略
| 策略 | 说明 |
|---|---|
| pairing | 需要配对批准(推荐) |
| allowlist | 只允许白名单用户 |
| open | 对所有人开放(不推荐) |
| disabled | 禁用 |
常见问题
Q: Gateway 启动后无法访问
检查步骤:
# 1. 检查 Gateway 是否运行
openclaw gateway status
# 2. 检查端口是否被占用
lsof -i :18789 # macOS/Linux
netstat -ano | findstr :18789 # Windows
# 3. 查看日志
openclaw logs --follow
# 4. 运行诊断
openclaw doctor
Q: Node 版本太低
# 使用 nvm 安装 Node 22
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 22
nvm use 22
Q: WSL2 服务在登出后停止
# 启用 lingering
sudo loginctl enable-linger $USER
Q: 如何更新 OpenClaw
# npm 全局安装的方式
npm update -g openclaw
# 或重新运行安装脚本
curl -fsSL https://openclaw.ai/install.sh | bash
Q: 如何备份数据
重点备份这些目录:
~/.openclaw/openclaw.json # 配置
~/.openclaw/workspace/ # 工作区(记忆、技能)
~/.openclaw/credentials/ # 凭证
下一步
完整文档:https://docs.openclaw.ai
Skills 市场:https://clawhub.com
社区支持:https://discord.com/invite/clawd
GitHub:GitHub - openclaw/openclaw: Your own personal AI assistant. Any OS. Any Platform. The lobster way. 🦞 · GitHub
教程基于 OpenClaw 官方文档整理,最后更新:2026-03-07
相关文章: