Windows (WSL2)

Windows (WSL2)

Windows 上的 OpenClaw 推荐通过 WSL2(推荐 Ubuntu)。 CLI + Gateway 在 Linux 内运行,这保持了 runtime 一致性并使工具更兼容(Node/Bun/pnpm、Linux binaries、skills)。原生 Windows 可能更棘手。WSL2 给你完整的 Linux 体验——一条命令安装:wsl --install

原生 Windows companion apps 计划中。

安装 (WSL2)

Gateway

Gateway service install (CLI)

在 WSL2 内:

openclaw onboard --install-daemon

或:

openclaw gateway install

或:

openclaw configure

提示时选择 Gateway service

修复/迁移:

openclaw doctor

Windows 登录前 Gateway 自动启动

对于无头设置,确保即使没有人登录 Windows 也能运行完整的启动链。

1) 保持用户服务在不登录的情况下运行

在 WSL 内:

sudo loginctl enable-linger "$(whoami)"

2) 安装 OpenClaw gateway 用户服务

在 WSL 内:

openclaw gateway install

3) 在 Windows 启动时自动启动 WSL

在 PowerShell 中作为管理员:

schtasks /create /tn "WSL Boot" /tr "wsl.exe -d Ubuntu --exec /bin/true" /sc onstart /ru SYSTEM

Ubuntu 替换为你的 distro 名称(来自):

wsl --list --verbose

验证启动链

重启后(Windows 登录前),从 WSL 检查:

systemctl --user is-enabled openclaw-gateway
systemctl --user status openclaw-gateway --no-pager

高级:通过 LAN 暴露 WSL 服务(portproxy)

WSL 有自己的虚拟网络。如果另一台机器需要访问WSL 内运行的服务(SSH、本地 TTS 服务器或 Gateway),你必须将 Windows 端口转发到当前 WSL IP。WSL IP 在重启后更改,因此你可能需要刷新转发规则。

示例(PowerShell 作为管理员):

$Distro = "Ubuntu-24.04"
$ListenPort = 2222
$TargetPort = 22

$WslIp = (wsl -d $Distro -- hostname -I).Trim().Split(" ")[0]
if (-not $WslIp) { throw "WSL IP not found." }

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$ListenPort `
  connectaddress=$WslIp connectport=$TargetPort

允许端口通过 Windows Firewall(一次性):

New-NetFirewallRule -DisplayName "WSL SSH $ListenPort" -Direction Inbound `
  -Protocol TCP -LocalPort $ListenPort -Action Allow

WSL 重启后刷新 portproxy:

netsh interface portproxy delete v4tov4 listenport=$ListenPort listenaddress=0.0.0.0 | Out-Null
netsh interface portproxy add v4tov4 listenport=$ListenPort listenaddress=0.0.0.0 `
  connectaddress=$WslIp connectport=$TargetPort | Out-Null

注意:

  • 从另一台机器 SSH 目标为 Windows host IP(示例:ssh user@windows-host -p 2222
  • 远程节点必须指向可访问的 Gateway URL(不是 127.0.0.1);使用 openclaw status --all 确认
  • 使用 listenaddress=0.0.0.0 进行 LAN 访问;127.0.0.1 仅限本地
  • 如果你想自动化,注册 Scheduled Task 在登录时运行刷新步骤

分步 WSL2 安装

1) 安装 WSL2 + Ubuntu

打开 PowerShell(管理员):

wsl --install
# 或明确选择 distro:
wsl --list --online
wsl --install -d Ubuntu-24.04

如果 Windows 要求则重启。

2) 启用 systemd(gateway install 所需)

在你的 WSL 终端:

sudo tee /etc/wsl.conf >/dev/null <<'EOF'
[boot]
systemd=true
EOF

然后从 PowerShell:

wsl --shutdown

重新打开 Ubuntu,然后验证:

systemctl --user status

3) 安装 OpenClaw(在 WSL 内)

在 WSL 内跟随 Linux Getting Started 流程:

git clone https://github.com/openclaw/openclaw.git
cd openclaw
pnpm install
pnpm ui:build # 首次运行自动安装 UI deps
pnpm build
openclaw onboard

完整指南:Getting Started

Windows companion app

我们还没有 Windows companion app。如果你想贡献使其实现,欢迎贡献。