OpenClaw WSL 安装指南

记录一下在 WSL (Ubuntu 24.04) 上从零安装 OpenClaw 的完整流程,包括国内镜像加速、Node 环境、模型配置和网关启动。

1. 准备 WSL 环境

如果需要重装发行版,先注销原有虚拟机:

1
wsl --unregister Ubuntu-24.04

再安装新的虚拟机(--web-download 走网络下载,比微软商店快):

1
wsl --install -d Ubuntu-24.04 --web-download

2. 换清华软件源

进入 WSL 后,写入清华源:

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo tee /etc/apt/sources.list.d/ubuntu.sources <<'EOF'
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu
Suites: noble noble-updates noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF

更新软件源缓存并安装 curl:

1
2
sudo apt update
sudo apt install curl -y

3. 安装 Node.js(nvm)

1
2
3
4
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install 24
nvm use 24

验证安装:

1
2
node -v
npm -v

4. npm 换源

国内直连 npm 很慢,换成 npmmirror:

1
2
npm config set registry https://registry.npmmirror.com
npm config get registry

5. 安装 OpenClaw

1
2
npm install -g openclaw@latest --allow-scripts=openclaw
openclaw --version

6. 配置模型和 API Key

1
openclaw config

按提示选择模型提供商并填入 API Key。

7. 启动网关

1
openclaw gateway

然后在浏览器访问 http://127.0.0.1:18789/ 即可打开控制台。

注意:如果 Windows 侧无法显示页面,需要到管理员 PowerShell 里放行 WSL 端口流量。

8. 配置文件参考

~/.openclaw/openclaw.json 的关键结构大致如下(token 和密钥务必换成你自己的):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
"agents": {
"defaults": {
"model": {
"primary": "qwen-token-plan/qwen3.8-flash"
}
},
"entries": {
"main": {
"model": {
"primary": "qwen-token-plan/qwen3.8-flash",
"fallbacks": [
"qwen-token-plan/qwen3.8-max",
"qwen-token-plan/qwen3.7-plus"
]
},
"identity": {
"name": "buntu",
"emoji": "🐧"
}
}
}
},
"gateway": {
"mode": "local",
"auth": {
"mode": "token",
"token": "your-secret-token"
}
},
"models": {
"mode": "merge",
"providers": {
"qwen-token-plan": {
"baseUrl": "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1",
"api": "openai-completions",
"models": []
}
}
}
}

几个要点:

  • agents.defaults.model.primary 是默认模型,entries.main.model.fallbacks 配置了主模型不可用时的回退顺序;
  • gateway.auth.token 是访问控制台的凭证,一定要改成随机字符串;
  • models.providers 里自定义了一个 OpenAI 兼容接口提供商,openclaw config 配好 API Key 后即可使用。

小结

整个流程核心就五步:WSL → 换源 → nvm/Node → npm 装 openclaw → 配置并启动网关。全程走国内镜像的话,半小时内可以搞定。

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2023-2026 BernieDif
  • Visitors: | Views:

请我喝杯茶吧~

支付宝
微信