Complete step-by-step installation guide for OpenClaw on Windows 10/11 with WSL2, includes common pitfalls and solutions from real installation experience.
Use this guide when you need to install OpenClaw on a Windows 10/11 machine via WSL2. 当你需要在 Windows 10/11 的 WSL2 环境中安装 OpenClaw 时,请使用本指南。
This guide includes: / 本指南包含:
1.1 Check Windows System Version / 检查 Windows 系统版本
Win + R, type winver, press Enter
Win + R,输入 winver,回车⚠️ Important Lesson from Pitfalls / 重要踩坑经验: If Windows 10 version is too old, it will lack
lxcore.sysandlxss.syskernel drivers, WSL will never start properly. You must upgrade system to latest version. 如果 Windows 10 版本太老,会缺少lxcore.sys和lxss.sys内核驱动,WSL 始终无法启动,必须升级系统到最新版本。
1.2 Verify CPU Virtualization is Enabled / 确认 CPU 虚拟化已开启
Ctrl + Shift + Esc to open Task Manager
Ctrl + Shift + Esc 打开任务管理器1.3 Prepare Terminal with Admin Privileges / 准备管理员权限终端 All following operations must be run as administrator: / 后续所有操作必须以管理员身份运行终端:
Win + X
Win + XUse Case / 适用场景: C: drive has ≥ 20GB free space, want fastest installation. 4 steps total, 5 minutes to complete. C 盘剩余空间 ≥ 20GB,想最快速度完成安装,选择这个方案。全程仅需 4 步,5 分钟完成。
2.1 Run One-click Install Command / 执行一键安装命令
wsl --install
This is official Microsoft one-click install, it automatically does: / 这是微软官方一键安装,会自动完成:
Wait for initialization to complete, follow prompt to create UNIX user account: / 等待初始化完成后,按提示创建 UNIX 用户账户:
# 1. Enter custom username (lowercase ASCII only, no spaces/Chinese, recommend "openclaw")
# 输入自定义用户名(纯英文小写,无空格/中文,推荐 openclaw)
Enter new UNIX username: openclaw
# 2. Enter custom password (no echo on screen, this is normal, remember it!)
# 输入自定义密码(输入时无字符回显,正常输入,务必牢记!)
New password:
# 3. Confirm password by entering again
# 再次输入密码确认
Retype new password:
2.2 Reboot to Activate Components / 重启电脑使组件生效
After command completes, you must reboot or system components won't take effect. 命令执行完成后,必须重启电脑,否则系统组件不会生效。
2.3 Verify Installation Success / 验证安装是否成功
wsl --list --verbose
Success Criteria (all must be true) / 成功标准(必须同时满足):
2.4 System Update & Mirror Configuration / 系统更新与软件源配置
Run inside WSL: / 进入 WSL 后执行:
sudo apt update
sudo apt upgrade -y
sudo apt install -y curl wget git
For users in China: Recommended to replace with Aliyun mirror for faster speed / 国内用户推荐替换阿里云镜像源加速:
sudo sed -i 's|http://archive.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list
sudo sed -i 's|http://security.ubuntu.com/ubuntu|https://mirrors.aliyun.com/ubuntu|g' /etc/apt/sources.list
sudo apt update && sudo apt upgrade -y
After completing, skip to Chapter 4. / 完成后跳转到第四章继续。
Use Case / 适用场景: C: drive doesn't have enough space, want to install WSL on another drive. 10 steps, ~15 minutes. C 盘空间不足,想把 WSL 安装到其他盘。全程 10 步,15 分钟完成。
Key Note / 核心说明: Official Microsoft wsl --install doesn't support custom install path directly. We use official standard method: "install core → export distro → import to target drive", which is safe.
微软官方 wsl --install 没有直接指定安装路径的参数,因此采用「装核心组件 → 导出发行版 → 导入到目标盘」的官方标准方案,安全无风险。
3.1 Install WSL Core Components (mandatory) / 安装 WSL 核心组件(必须先做)
Run these commands one-by-one in admin terminal: / 在管理员终端中依次执行:
# Enable WSL core feature / 启用 WSL 核心组件
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# Enable Virtual Machine Platform feature / 启用虚拟机平台组件
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# !! PITFALL WARNING !! System built-in wsl.exe is too old, need manual install latest version
# 这里有坑:系统自带 wsl.exe 版本太旧,需要手动安装最新版
# Download from: https://github.com/microsoft/WSL/releases/latest
# After install, add new WSL to PATH with higher priority:
# $oldPath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
# [System.Environment]::SetEnvironmentVariable("Path", "C:\Program Files\WSL;" + $oldPath, "Machine")
# Enable all Hyper-V core components (mandatory, otherwise WSL won't start)
# 启用所有 Hyper-V 核心组件(必须,否则 WSL 无法启动)
Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Services -All -NoRestart
bcdedit /set hypervisorlaunchtype auto
# Set WSL2 as default version / 设置 WSL2 为默认版本
wsl --set-default-version 2
After execution, you must reboot for components to activate. / 执行完成后,必须重启电脑,使组件生效。
⚠️ Common Pitfall / 常见坑: If
wsl --set-default-version 2only prints help text and doesn't execute, that means built-in wsl.exe is too old. You must manually download and install latest WSL MSI package. 如果wsl --set-default-version 2只打印帮助文档不执行,说明系统自带的 wsl.exe 太旧,必须手动下载安装最新版 WSL MSI 包。
3.2 Install Ubuntu Distro to Temporary Location / 安装 Ubuntu 发行版到临时目录
After reboot, open admin terminal again, install Ubuntu 22.04 LTS (stable): / 重启后再次打开管理员终端,安装 Ubuntu 22.04 LTS 稳定版:
wsl --install -d Ubuntu-22.04
3.3 Terminate Distro to Prevent Auto-Initialization / 终止发行版,避免自动初始化
After installation, DO NOT open Ubuntu app (it will auto-initialize on C: drive), just run: / 安装完成后,绝对不要打开 Ubuntu 应用(否则会自动初始化占用 C 盘),直接执行:
wsl --terminate Ubuntu-22.04
3.4 Create Install Directory on Target Drive / 在目标盘创建安装目录
Open File Explorer, on target drive (e.g. D:), create: / 打开文件资源管理器,在目标盘(如 D 盘)创建:
D:\WSL\backup / 导出文件临时目录:D:\WSL\backupD:\WSL\Ubuntu2204 / 最终安装目录:D:\WSL\Ubuntu2204❗ Critical Pitfall Avoidance / 关键避坑: Directory path MUST NOT contain Chinese characters, spaces, or special characters, otherwise import will fail. 目录路径绝对不要有中文、空格、特殊字符,否则会导致导入失败。
3.5 Export Distro to Temp File / 导出发行版到临时文件
# Format: wsl --export <distro-name> <full-export-path>
# 命令格式:wsl --export 发行版名称 导出文件完整路径
wsl --export Ubuntu-22.04 D:\WSL\backup\ubuntu2204.tar
Wait for export to complete, takes 1-3 minutes depending on disk speed. No error means success. / 等待导出完成,根据磁盘速度约 1-3 分钟,无报错即为成功。
3.6 Unregister Default Distro on C: / 注销 C 盘的默认发行版
# Format: wsl --unregister <distro-name>
# 命令格式:wsl --unregister 发行版名称
wsl --unregister Ubuntu-22.04
After execution, the C: drive distro files are completely removed. / 执行后,C 盘的发行版文件会被完全删除。
3.7 Import Distro to Target Drive / 导入发行版到目标盘
# Format: wsl --import <custom-distro-name> <target-install-dir> <exported-tar-path> --version 2
# 命令格式:wsl --import 自定义发行版名称 目标安装目录 导出 tar 文件路径 --version 2
wsl --import Ubuntu-22.04 D:\WSL\Ubuntu2204 D:\WSL\backup\ubuntu2204.tar --version 2
Parameter Explanation / 参数说明:
Ubuntu-22.04: Custom distro name, use this name to boot later / 自定义的发行版名称,后续启动用这个名字D:\WSL\Ubuntu2204: Target install directory, all WSL files stored here / 目标安装目录,WSL 所有文件都会存放在这里--version 2: Force use WSL2 version this is mandatory / 强制使用 WSL2 版本,必须添加3.8 Set Default Login User (CRITICAL!) / 设置默认登录用户(关键!)
After import, default login is root. You can choose: / 导入完成后默认会以 root 身份登录,你有两种选择:
First enter the imported Ubuntu system: / 先进入导入的 Ubuntu 系统:
wsl -d Ubuntu-22.04
Run these commands in order (replace openclaw with your username): / 进入系统后依次执行(替换 openclaw 为你的用户名):
# 1. Create user, auto-create home dir, set default shell to bash
# 创建用户,自动创建家目录,设置默认 shell 为 bash
useradd -m -s /bin/bash openclaw
# 2. Set password for user (no echo on screen, normal behavior, remember it!)
# 给用户设置密码(输入时无回显,务必牢记)
passwd openclaw
# 3. Add user to sudo group for admin privileges
# 给用户赋予 sudo 管理员权限
usermod -aG sudo openclaw
# 4. Configure WSL default login to be the newly created user
# 配置 WSL 默认登录用户为刚创建的用户
echo -e "[user]\ndefault = openclaw" >> /etc/wsl.conf
# 5. (Recommended) Configure passwordless sudo to avoid repeated typing during install
# 配置 sudo 免密(推荐,避免安装过程频繁输入密码)
echo "openclaw ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
After complete, type exit to leave WSL, back to Windows terminal. / 执行完成后,输入 exit 退出 WSL,回到 Windows 终端。
3.9 Restart WSL to Activate Configuration / 重启 WSL 使配置生效
# Terminate distro / 终止发行版
wsl --terminate Ubuntu-22.04
# Re-enter system, verify default user / 重新进入系统,验证默认用户
wsl -d Ubuntu-22.04
Success Criteria / 成功标准: After entering system, prompt shows your created username (e.g. openclaw@...), NOT root. / 进入系统后,命令行前缀显示你创建的用户名(如 openclaw@...),而非 root。
If you prefer simplicity and don't want to create a separate user, you can just keep using root. No extra configuration needed. 如果你喜欢简单,不想创建单独用户,可以直接一直用 root 登录,不需要任何额外配置。
Main differences / 主要区别:
Both options work fine for installing and running OpenClaw. / 两种方式都能正常安装和运行 OpenClaw,按个人习惯选择即可。
3.10 Verify Install Path & Version / 验证安装路径与版本
wsl --list --verbose
Success Criteria / 成功标准:
4.1 Configure .wslconfig (Optimize Network & Memory) / 配置 .wslconfig(优化网络和内存)
Mirror networking mode needs global configuration: / 镜像网络模式需要全局配置:
C:\Users\<your-username>\ / 打开文件资源管理器,导航到:C:\Users\<你的用户名>\.wslconfig (note the leading dot) / 创建名为 .wslconfig 的文件(注意前面的点号)[wsl2]
# Enable mirrored networking mode - THIS IS THE MOST IMPORTANT CONFIG
# 启用镜像网络模式 - 这是最重要的配置
networkingMode=mirrored
# Enable DNS tunneling, prevents DNS resolution failure under VPN
# 启用 DNS 隧道,防止 VPN 环境下域名解析失效
dnsTunneling=true
# Force WSL to use Windows HTTP proxy settings
# 强制 WSL 使用 Windows 的 HTTP 代理设置
autoProxy=true
# Enable integrated firewall support
# 启用集成防火墙支持
firewall=true
[experimental]
# Gradually auto-reclaim unused memory, improves performance
# 自动回收闲置内存,优化性能
autoMemoryReclaim=gradual
# Enable host loopback access support
# 支持主机回环地址访问
hostAddressLoopback=true
wsl --shutdown
4.2 Configure Windows Firewall Rule / 配置 Windows 防火墙规则
In mirrored networking mode, need to allow OpenClaw port access: / 镜像网络模式下,需要允许 OpenClaw 端口访问:
New-NetFirewallRule -DisplayName "OpenClaw-Service" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 18789
⚠️ Note / 说明: Windows 10 doesn't support mirrored networking mode, it will automatically fall back to NAT mode. This doesn't affect normal OpenClaw usage. Windows 10 不支持镜像网络模式,会自动回退到 NAT 模式,不影响 OpenClaw 正常使用。
4.3 Install OpenClaw / 安装 OpenClaw
Run after entering WSL: / 进入 WSL 后执行:
curl -fsSL https://molt.bot/install.sh | bash
4.4 Fix PATH Environment Variable / 修复 PATH 环境变量
If after installation it says openclaw command not found, that means npm global bin directory isn't in PATH: / 如果安装完成后提示 openclaw 命令找不到,说明 npm 全局 bin 目录没有加入 PATH:
echo 'export PATH="/home/openclaw/.npm-global/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Verify: / 验证:
which openclaw
openclaw --version
4.5 Run Initialization Wizard / 运行初始化向导
openclaw setup
Follow the wizard prompts to complete configuration. / 按照向导提示完成配置即可。
After installing OpenClaw, you need to configure your own LLM API key in the setup wizard. You can choose any LLM provider that fits your needs. Common options include: 安装完成后,你需要在安装向导中配置自己的 LLM API 密钥。你可以根据需求选择任意 LLM 服务商,常见选项包括:
Start OpenClaw / 启动 OpenClaw:
# 1. From Windows PowerShell
wsl -d Ubuntu
# 2. Inside WSL
openclaw gateway start
Verify Installation / 验证安装:
which openclaw
openclaw --version
openclaw gateway status
This section collects troubleshooting experience from Deepwhite 深白色, workfisher, and other community contributors who installed OpenClaw on Windows WSL2. 本节收集了作者 Deepwhite 深白色、workfisher 以及社区其他人在 Windows WSL2 安装 OpenClaw 实际遇到的各种报错和解决方法。
wsl --update, wsl --set-default-version 2 only prints help text, doesn't execute / wsl --update、wsl --set-default-version 2 只打印帮助文档不执行curl -fSL https://ghproxy.com/https://github.com/microsoft/WSL/releases/download/2.3.26/wsl.2.3.26.0.x64.msi -o wsl-install.msi
wsl --status constantly reports WSL_E_WSL_OPTIONAL_COMPONENT_REQUIRED / wsl --status 持续报 WSL_E_WSL_OPTIONAL_COMPONENT_REQUIREDMicrosoft-Hyper-V-Hypervisor are not enabled by default / Microsoft-Hyper-V-Hypervisor 等核心组件默认未开启Enable-WindowsOptionalFeature / 逐一用 Enable-WindowsOptionalFeature 启用所有 Hyper-V 组件(详见第三章)lxcore.sys and lxss.sys kernel drivers are missing / lxcore.sys 和 lxss.sys 两个关键内核驱动不存在apt update speed under 20KB/s / apt update 速度 20KB/s 以下PATH missing npm global bin dir / 安装完 OpenClaw 后提示 PATH missing npm global bin dir/home/openclaw/.npm-global/bin not added to PATH / npm 全局安装路径 /home/openclaw/.npm-global/bin 未加入 PATHsudo tee /etc/wsl.conf << 'EOF'
[boot]
systemd=true
EOF
Then run in Windows PowerShell: / 然后在 Windows PowerShell 执行:
wsl --shutdown
Restart WSL then start OpenClaw again / 重启 WSL 后再启动 OpenClaw。
Gateway service disabled / 启动后提示 Gateway service disabledopenclaw gateway install
systemctl --user start openclaw-gateway.service
Then check status: / 然后检查状态:
openclaw gateway status
wsl --install fails with error code 0x80070005 / wsl --install 失败,错误代码 0x80070005Enable-WindowsOptionalFeature fails with error / Enable-WindowsOptionalFeature 执行失败wsl --list --verbose shows no distributions / wsl --list --verbose 显示没有发行版# Change ownership of npm directory to current user
sudo chown -R $USER:$USER ~/.npm-global
Then re-run install / 然后重新运行安装命令。
# Run in Windows PowerShell
wsl --shutdown
Restart WSL, time will sync automatically / 关闭 WSL 再重新启动,时间会自动同步。
[wsl2]
swap=0
wsl --install error: need to update kernel / 问题 1:执行 wsl --install 报错,提示需要更新内核wsl --list --verbose shows VERSION is 1, not 2 / 问题 2:wsl --list --verbose 显示 VERSION 是 1,不是 2wsl --set-default-version 2 / 执行 wsl --set-default-version 2wsl --set-version <your-distro-name> 2, wait for conversion to complete / 执行 wsl --set-version <你的发行版名称> 2,等待转换完成wsl -d <distro-name> -u root in Windows terminal to login as root / 在 Windows 终端执行 wsl -d <发行版名称> -u root,以 root 身份进入系统passwd <your-username> to reset password / 执行 passwd <你的用户名>,重新设置密码exit and login with new password / 执行 exit 退出,用新密码登录即可.wslconfig is in correct user directory, filename correct (must be .wslconfig, not wslconfig.txt) / 确认 .wslconfig 文件放在正确的用户目录下,文件名正确(必须是 .wslconfig,不是 wslconfig.txt)wsl --shutdown to fully close WSL, wait 10 seconds then restart / 执行 wsl --shutdown 完全关闭 WSL,等待 10 秒后再启动wsl --update to update WSL to latest version / 执行 wsl --update 更新 WSL 到最新版本D:\WSL\Ubuntu2204, do NOT use paths with spaces/Chinese. / 检查目标路径是否有中文、空格、特殊字符,换成纯英文路径,比如 D:\WSL\Ubuntu2204,不要使用带空格/中文的路径。http://localhost:18789 doesn't load from browser / 在 WSL 中 OpenClaw 在运行,但浏览器访问 http://localhost:18789 打不开hostname -I inside WSL, then access http://<wsl-ip>:18789 / NAT 模式:在 WSL 内用 hostname -I 获取 IP,然后访问 http://<wsl-ip>:18789Install Chrome extension for quick access: / 安装 Chrome 扩展方便快捷连接: