本指南提供在 Windows 系统上安装 OpenClaw 的完整详细步骤,每一步都包含具体的命令和预期结果。
📋 目录
-
[安装 OpenClaw](#安装 OpenClaw "#%E5%AE%89%E8%A3%85-openclaw")
-
[配置 OpenClaw](#配置 OpenClaw "#%E9%85%8D%E7%BD%AE-openclaw")
安装前准备
步骤 1:检查 Windows 版本
-
按
Win + R键 -
输入
winver并按 Enter -
确认 Windows 版本为 Windows 10 或更高
预期结果:显示 Windows 10/11 版本信息
步骤 2:以管理员身份打开 PowerShell
-
点击开始菜单
-
搜索 "PowerShell"
-
右键点击 "Windows PowerShell"
-
选择 "以管理员身份运行"
预期结果:PowerShell 窗口标题显示"管理员"
步骤 3:配置 PowerShell 执行策略
在管理员 PowerShell 中执行:
powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
当提示输入选项时,输入 Y 并按 Enter
预期结果:
scss
执行策略更改
执行策略可帮助防止执行不信任的脚本。如果更改执行策略,可能会使你面临 about_Execution_Policies
帮助主题中所述的安全风险。是否要更改执行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认为"N"): Y
安装必要软件
步骤 4:安装 Node.js
-
访问 Node.js 官网:nodejs.org/
-
下载 LTS 版本(推荐 20.x 或更高)
-
运行安装程序
-
按照向导完成安装(全部使用默认设置)
验证安装:
powershell
node --version
npm --version
预期结果:
v20.x.x
10.x.x
步骤 5:安装 Git
-
访问 Git 官网:git-scm.com/download/wi...
-
下载 Windows 版 Git
-
运行安装程序
-
安装选项:
-
选择 "Git from the command line and also from 3rd-party software"
-
使用默认的编辑器(Vim)
-
选择 "Use Git from the Windows Command Prompt"
-
其他选项使用默认值
验证安装:
powershell
git --version
预期结果:
git version 2.x.x
步骤 6:配置 Git
powershell
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global core.autocrlf true
验证配置:
powershell
git config --list
预期结果:显示包含 user.name 和 user.email 的配置列表
配置环境
步骤 7:配置 npm 使用国内镜像源
powershell
npm config set registry https://registry.npmmirror.com
验证配置:
powershell
npm config get registry
预期结果:
arduino
https://registry.npmmirror.com
步骤 8:配置 Git 使用 HTTPS 协议
powershell
git config --global url."https://github.com/".insteadOf ssh://git@github.com/
git config --global url."https://github.com/".insteadOf git@github.com:
验证配置:
powershell
git config --list | findstr url
预期结果:
perl
url.https://github.com/.insteadof=ssh://git@github.com/
url.https://github.com/.insteadof=git@github.com:
步骤 9:清除 npm 缓存
powershell
npm cache clean --force
预期结果:
sql
npm WARN using --force
I sure hope you know what you are doing.
安装 OpenClaw
步骤 10:查看 OpenClaw 可用版本
powershell
npm view openclaw versions --json
预期结果:显示所有可用版本的列表
步骤 11:安装 OpenClaw(推荐方法)
方法 A:使用 npm 安装(推荐)
powershell
npm install -g openclaw@latest --legacy-peer-deps
预期结果:
added XX packages in XXs
方法 B:如果方法 A 失败,尝试安装旧版本
powershell
npm install -g openclaw@2026.3.12 --legacy-peer-deps
方法 C:如果 npm 安装失败,使用 cnpm
powershell
# 安装 cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com
# 使用 cnpm 安装 OpenClaw
cnpm install -g openclaw@latest
步骤 12:验证 OpenClaw 安装
powershell
openclaw --version
预期结果:
openclaw/2026.3.13 win32-x64 node-v20.x.x
如果提示找不到命令:
powershell
# 查看 npm 全局安装路径
npm config get prefix
# 查看 npm 全局 bin 路径
npm bin -g
# 手动添加到 PATH(临时)
$env:PATH += ";$(npm bin -g)"
# 再次验证
openclaw --version
永久添加到 PATH:
-
右键点击"此电脑" → "属性"
-
点击"高级系统设置"
-
点击"环境变量"
-
在"用户变量"中找到 "Path"
-
点击"编辑"
-
点击"新建"
-
添加 npm 全局 bin 路径(例如:
C:\Users\你的用户名\AppData\Roaming\npm) -
点击"确定"保存所有更改
-
关闭所有 PowerShell 窗口,重新打开
配置 OpenClaw
步骤 13:初始化 OpenClaw
powershell
openclaw init
向导会询问以下问题:
问题 1:Gateway 运行位置
-
输入:
local -
按 Enter
问题 2:认证方式
-
输入:
oauth(推荐)或api-key -
按 Enter
问题 3:工作区路径
- 直接按 Enter 使用默认值(
C:\Users\你的用户名\.openclaw\workspace)
问题 4:端口配置
- 直接按 Enter 使用默认值(
3000)
预期结果:
arduino
✓ OpenClaw initialized successfully
✓ Configuration saved to C:\Users\你的用户名\.openclaw\config.json
步骤 14:检查配置文件
powershell
notepad $env:USERPROFILE\.openclaw\config.json
预期内容:
json
{
"gateway": {
"mode": "local",
"host": "localhost",
"port": 3000,
"auth": {
"enabled": true,
"type": "token"
}
},
"workspace": "C:\\Users\\你的用户名\\.openclaw\\workspace",
"logging": {
"level": "info"
}
}
步骤 15:创建必要的目录
powershell
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.openclaw\credentials"
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.openclaw\workspace"
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.openclaw\agents"
预期结果:无错误提示,目录创建成功
启动服务
步骤 16:启动 OpenClaw Gateway
powershell
openclaw start
预期结果:
csharp
✓ OpenClaw Gateway started successfully
✓ Listening on http://localhost:3000
✓ Workspace: C:\Users\你的用户名\.openclaw\workspace
步骤 17:检查服务状态
powershell
openclaw status
预期结果:
yaml
Gateway Status: Running
PID: 12345
Port: 3000
Uptime: 0:00:05
步骤 18:查看日志
powershell
openclaw logs
预期结果:显示实时日志输出
按 Ctrl + C 停止查看日志(不会停止服务)
配置认证
步骤 19:使用 Anthropic OAuth 认证(推荐)
powershell
openclaw auth oauth
预期结果:
r
Opening browser for OAuth authentication...
浏览器会自动打开,执行以下操作:
-
登录你的 Anthropic 账户(Claude Pro/Max)
-
授权 OpenClaw 访问
-
复制显示的
code#state值
在 PowerShell 中粘贴并验证:
powershell
openclaw auth verify "YOUR_CODE#STATE_VALUE"
预期结果:
css
✓ OAuth authentication successful
✓ Credentials saved to C:\Users\你的用户名\.openclaw\credentials\oauth.json
步骤 20:验证认证状态
powershell
openclaw auth status
预期结果:
yaml
Authentication Status: ✓ Connected
Provider: Anthropic OAuth
Account: your@email.com
Expires: 2026-04-15
备选方案:使用 API Key
如果你有 Anthropic API Key:
powershell
openclaw auth api-key YOUR_ANTHROPIC_API_KEY
验证安装
步骤 21:健康检查
powershell
curl http://localhost:3000/health
如果没有 curl,使用 PowerShell:
powershell
Invoke-WebRequest -Uri http://localhost:3000/health -UseBasicParsing | Select-Object -ExpandProperty Content
预期结果:
json
{
"status": "healthy",
"version": "2026.3.13",
"uptime": 123
}
步骤 22:测试 AI 调用
powershell
openclaw chat "Hello, can you hear me?"
预期结果:
vbnet
Assistant: Yes, I can hear you! I'm ready to help you with your tasks.
步骤 23:检查工作区文件
powershell
Get-ChildItem $env:USERPROFILE\.openclaw\workspace
预期结果:
AGENTS.md
IDENTITY.md
USER.md
SOUL.md
配置开机自启动(可选)
步骤 24:创建启动脚本
创建文件 C:\start-openclaw.ps1:
powershell
# 创建启动脚本
@"
@echo off
echo Starting OpenClaw...
cd /d %USERPROFILE%
openclaw start
timeout /t 3 /nobreak >nul
echo OpenClaw started successfully!
pause
"@ | Out-File -FilePath "C:\start-openclaw.bat" -Encoding ASCII
步骤 25:添加到启动文件夹
-
按
Win + R -
输入
shell:startup并按 Enter -
将
C:\start-openclaw.bat的快捷方式复制到启动文件夹
步骤 26:验证开机启动
-
重启电脑
-
打开 PowerShell
-
执行:
powershell
openclaw status
预期结果:显示服务正在运行
常见问题解决
问题 1:PowerShell 执行策略错误
症状:
无法加载文件,因为在此系统上禁止运行脚本
解决方案:
powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
问题 2:找不到 openclaw 命令
症状:
arduino
openclaw : 无法将"openclaw"项识别为 cmdlet、函数、脚本文件或可运行程序的名称
解决方案:
powershell
# 临时添加到 PATH
$env:PATH += ";$(npm bin -g)"
# 永久添加(需要重启 PowerShell)
[System.Environment]::SetEnvironmentVariable('Path', $env:Path + ";$(npm bin -g)", [System.EnvironmentVariableTarget]::User)
问题 3:端口被占用
症状:
vbnet
Error: Port 3000 is already in use
解决方案:
powershell
# 查找占用端口的进程
netstat -ano | findstr :3000
# 杀死进程(替换 PID)
taskkill /PID 进程ID /F
# 或者更改端口
openclaw configure --port 3001
问题 4:Git SSH 权限错误
症状:
java
git@github.com: Permission denied (publickey)
解决方案:
powershell
git config --global url."https://github.com/".insteadOf ssh://git@github.com/
git config --global url."https://github.com/".insteadOf git@github.com:
问题 5:依赖安装失败
症状:
typescript
Error: An unknown git error occurred
解决方案:
powershell
# 方法 1:使用 legacy peer deps
npm install -g openclaw@latest --legacy-peer-deps
# 方法 2:清除缓存重试
npm cache clean --force
npm install -g openclaw@latest --legacy-peer-deps
# 方法 3:使用旧版本
npm install -g openclaw@2026.3.12 --legacy-peer-deps
问题 6:服务无法启动
症状:
vbnet
Error: Failed to start Gateway
解决方案:
powershell
# 查看详细日志
openclaw logs --verbose
# 检查配置文件
notepad $env:USERPROFILE\.openclaw\config.json
# 重置配置
Remove-Item $env:USERPROFILE\.openclaw\config.json -Force
openclaw init
完整安装检查清单
在完成所有步骤后,确认以下项目:
基础环境
-
Windows 10/11 已确认
-
PowerShell 以管理员身份运行
-
执行策略已配置
-
Node.js 已安装(v20.x 或更高)
-
npm 已安装(v10.x 或更高)
-
Git 已安装并配置
环境配置
-
npm 镜像源已配置
-
Git HTTPS 协议已配置
-
npm 缓存已清除
OpenClaw 安装
-
OpenClaw 已全局安装
-
openclaw --version命令可用 -
配置文件已创建
-
工作区目录已创建
服务配置
-
Gateway 服务已启动
-
服务状态检查通过
-
认证已配置
-
认证状态检查通过
验证测试
-
健康检查通过
-
测试 AI 调用成功
-
工作区文件已生成
-
日志输出正常
快速命令参考
服务管理
powershell
openclaw start # 启动服务
openclaw stop # 停止服务
openclaw restart # 重启服务
openclaw status # 查看状态
openclaw logs # 查看日志
配置管理
powershell
openclaw init # 初始化配置
openclaw configure # 重新配置
openclaw config show # 查看配置
认证管理
powershell
openclaw auth oauth # OAuth 认证
openclaw auth status # 查看认证状态
openclaw auth logout # 登出
常用系统命令
powershell
$env:USERPROFILE # 用户主目录
$env:PATH # PATH 环境变量
npm config get prefix # npm 全局路径
npm bin -g # npm 全局 bin 路径
技术支持
获取帮助
-
OpenClaw 官方文档 : docs.openclaw.ai
-
OpenClaw GitHub : github.com/openclaw/op...
-
问题反馈 : github.com/openclaw/op...
日志位置
-
OpenClaw 配置 :
C:\Users\你的用户名\.openclaw\ -
npm 缓存 :
C:\Users\你的用户名\AppData\Local\npm-cache\ -
npm 日志 :
C:\Users\你的用户名\AppData\Local\npm-cache\_logs\