OpenClaw Windows 完整安装指南

本指南提供在 Windows 系统上安装 OpenClaw 的完整详细步骤,每一步都包含具体的命令和预期结果。

📋 目录

  1. 安装前准备

  2. 安装必要软件

  3. 配置环境

  4. [安装 OpenClaw](#安装 OpenClaw "#%E5%AE%89%E8%A3%85-openclaw")

  5. [配置 OpenClaw](#配置 OpenClaw "#%E9%85%8D%E7%BD%AE-openclaw")

  6. 启动服务

  7. 验证安装

  8. 常见问题解决


安装前准备

步骤 1:检查 Windows 版本

  1. Win + R

  2. 输入 winver 并按 Enter

  3. 确认 Windows 版本为 Windows 10 或更高

预期结果:显示 Windows 10/11 版本信息

步骤 2:以管理员身份打开 PowerShell

  1. 点击开始菜单

  2. 搜索 "PowerShell"

  3. 右键点击 "Windows PowerShell"

  4. 选择 "以管理员身份运行"

预期结果: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

  1. 访问 Node.js 官网:nodejs.org/

  2. 下载 LTS 版本(推荐 20.x 或更高)

  3. 运行安装程序

  4. 按照向导完成安装(全部使用默认设置)

验证安装

powershell 复制代码
node --version

npm --version

预期结果

复制代码
v20.x.x

10.x.x

步骤 5:安装 Git

  1. 访问 Git 官网:git-scm.com/download/wi...

  2. 下载 Windows 版 Git

  3. 运行安装程序

  4. 安装选项:

  • 选择 "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

  1. 右键点击"此电脑" → "属性"

  2. 点击"高级系统设置"

  3. 点击"环境变量"

  4. 在"用户变量"中找到 "Path"

  5. 点击"编辑"

  6. 点击"新建"

  7. 添加 npm 全局 bin 路径(例如:C:\Users\你的用户名\AppData\Roaming\npm

  8. 点击"确定"保存所有更改

  9. 关闭所有 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...

浏览器会自动打开,执行以下操作:

  1. 登录你的 Anthropic 账户(Claude Pro/Max)

  2. 授权 OpenClaw 访问

  3. 复制显示的 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:添加到启动文件夹

  1. Win + R

  2. 输入 shell:startup 并按 Enter

  3. C:\start-openclaw.bat 的快捷方式复制到启动文件夹

步骤 26:验证开机启动

  1. 重启电脑

  2. 打开 PowerShell

  3. 执行:

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 配置 : C:\Users\你的用户名\.openclaw\

  • npm 缓存 : C:\Users\你的用户名\AppData\Local\npm-cache\

  • npm 日志 : C:\Users\你的用户名\AppData\Local\npm-cache\_logs\

相关推荐
Victor3563 小时前
MongoDB(87)如何使用GridFS?
后端
Victor3563 小时前
MongoDB(88)如何进行数据迁移?
后端
小红的布丁4 小时前
单线程 Redis 的高性能之道
redis·后端
GetcharZp4 小时前
Go 语言只能写后端?这款 2D 游戏引擎刷新你的认知!
后端
宁瑶琴5 小时前
COBOL语言的云计算
开发语言·后端·golang
普通网友5 小时前
阿里云国际版服务器,真的是学生党的性价比之选吗?
后端·python·阿里云·flask·云计算
IT_陈寒6 小时前
Vue的这个响应式问题,坑了我整整两小时
前端·人工智能·后端
Soofjan7 小时前
Go 内存回收-GC 源码1-触发与阶段
后端
shining7 小时前
[Golang]Eino探索之旅-初窥门径
后端
掘金者阿豪7 小时前
Mac 程序员效率神器:6 个我每天都在用的 Mac 工具推荐(Alfred / Paste / PixPin / HexHub / iTerm2 /)
后端