Windows WSL2 安装 OpenClaw 教程
# Windows WSL2 安装 OpenClaw 教程
在 Windows 11/10 上通过 WSL2 Ubuntu 安装 OpenClaw
前置要求
- Windows 11 或 Windows 10 (20H2+)
- WSL2 已启用
- 8GB+ RAM (建议16GB)
第一步:启用 WSL2
以管理员身份打开 PowerShell:
powershell
# 启用 WSL 功能
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# 启用虚拟机平台
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# 设置 WSL2 为默认
wsl --set-default-version 2第二步:安装 Ubuntu
打开 Microsoft Store,搜索 "Ubuntu 22.04" 或 "Ubuntu 24.04",点击安装。
安装完成后打开 Ubuntu,设置用户名和密码。
第三步:在 Ubuntu 中安装 OpenClaw
bash
# 更新系统
sudo apt update && sudo apt upgrade -y
# 安装 Node.js 20
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# 安装 PostgreSQL
sudo apt install -y postgresql postgresql-contrib
sudo systemctl start postgresql
# 创建数据库
sudo -u postgres createuser -s openclaw
sudo -u postgres createdb openclaw
sudo -u postgres psql -c "ALTER USER openclaw WITH PASSWORD 'password123';"
# 克隆项目
cd ~
git clone https://github.com/openclaw/openclaw.git
cd openclaw
# 安装依赖
npm install
# 配置
cp .env.example .env
nano .env配置内容:
env
DATABASE_URL=postgresql://openclaw:password123@localhost:5432/openclaw
JWT_SECRET=any-secret-key-here
AI_PROVIDER=openai
OPENAI_API_KEY=sk-your-key
PORT=3000bash
# 初始化数据库
npx prisma generate
npx prisma db push
# 启动开发服务器
npm run dev第四步:Windows 访问
WSL2 运行后,在 Windows 浏览器访问:
text
http://localhost:3000第五步:使用 VS Code 开发 (推荐)
bash
# 在 VS Code 中打开
cd openclaw
code .常见问题
WSL2 内存占用高
创建 ~/.wslconfig 文件:
ini
[wsl2]
memory=4GB
processors=2然后重启 WSL:
powershell
wsl --shutdown端口 3000 被占用
在 .env 中修改 PORT 为其他端口,如 3001。
---
推荐配套:
- [Ubuntu 安装指南](/post/install-openclaw-ubuntu)
- [Docker 安装](/post/install-openclaw-docker)
相关文章
Ubuntu/Debian 系统安装 OpenClaw 完整指南
详细步骤指南:在 Ubuntu 和 Debian 系统上安装 OpenClaw AI 助手平台,包含开发环境和生产环境配置。
2026-03-20CentOS/RHEL 系统安装 OpenClaw 指南
# CentOS/RHEL 系统安装 OpenClaw 指南 > 本教程详细介绍如何在 CentOS Stream 9 或 RHEL 9 上安装 OpenClaw ## 环境要求 - CentO
2026-03-20macOS 安装 OpenClaw 指南
# macOS 安装 OpenClaw 指南 > 在 Mac 上安装 OpenClaw AI 助手平台 ## 环境要求 - macOS 12 (Monterey) 或更高版本 - 4GB+ RA
2026-03-20