Windows下载OpenClaw源码,启动和安装攻略

4 阅读2分钟

关注前端小讴,阅读更多原创技术文章

官方文档 →

安装向导

  • 1.安装node,推荐版本24,最低版本22.16+,推荐使用nvm控制node版本

  • 2.安装pnpm npm install -g pnpm

  • 3.克隆并构建

    • git clone https://github.com/openclaw/openclaw.git
    • cd openclaw
    • pnpm install
    • pnpm ui:build
    • pnpm build
  • 4.链接cli,让openclaw命令全局可用 pnpm link --global

验证:命令行输入openclaw,有相关提示

报错及解决方法

  • 用管理员打开命令行/powershell

  • pnpm install报错Error error code 3221225477

    • 降级node22版本
    • 安装C++构建工具
    • 运行安装器,工作负载列表中只勾选“使用 C++ 的桌面开发”
    • 完成后需重启电脑,重新install即可(建议删掉node_modulespnpm-lock.yaml并执行pnpm store prune

    参考方案 →

  • pnpm build报错scripts/bundle-a2ui.sh: line 31: node: command not found

    • 创建scripts/bundle-a2ui.mjs

      // scripts/bundle-a2ui.mjs
      // OpenClaw A2UI Bundle Placeholder Generator
      // For public repository users who do not have access to private A2UI source code.
      // This script creates a minimal valid ES module to satisfy TypeScript compilation.
      
      import fs from "node:fs";
      import path from "node:path";
      import { createHash } from "node:crypto";
      import { fileURLToPath } from "node:url";
      
      // ── Resolve project root directory correctly on Windows and Unix ──
      const __filename = fileURLToPath(import.meta.url);
      const __dirname = path.dirname(__filename);
      const ROOT_DIR = path.resolve(__dirname, ".."); // openclaw/ root
      
      // ── Define output paths ──
      const OUTPUT_DIR = path.join(ROOT_DIR, "src", "canvas-host", "a2ui");
      const OUTPUT_FILE = path.join(OUTPUT_DIR, "a2ui.bundle.js");
      const HASH_FILE = path.join(OUTPUT_DIR, ".bundle.hash");
      
      // ── Ensure output directory exists ──
      fs.mkdirSync(OUTPUT_DIR, { recursive: true });
      
      // ── Generate placeholder content (valid ES module) ──
      const placeholderContent =
        `
      
      // Auto-generated placeholder for A2UI
      
      // Source code is not available in the public OpenClaw repository.
      
      // This file exists only to satisfy build dependencies.
      
      export const A2UI = {
      
      version: '0.0.0-placeholder',
      
      render: () => {
      
      throw new Error('A2UI runtime is not available in this build.');
      
      }
      
      };
      
      `.trim() + "\n";
      
      // ── Write the bundle file ──
      fs.writeFileSync(OUTPUT_FILE, placeholderContent);
      
      // ── Compute and write hash to prevent unnecessary rebuilds ──
      const hash = createHash("sha256").update(placeholderContent).digest("hex");
      fs.writeFileSync(HASH_FILE, hash);
      
      // ── Success message ──
      console.log("✅ A2UI placeholder bundle created successfully.");
      console.log(` Bundle: ${OUTPUT_FILE}`);
      console.log(` Hash: ${HASH_FILE}`);
      
    • package.json中替换脚本

      {
        "scripts": {
          //...
          "canvas:a2ui:bundle": "node --import tsx scripts/bundle-a2ui.mjs"
        }
      }
      

    参考方案 →

新手向导

openclaw onboard --install-daemon

  • I understand this is personal-by-default and shared/multi-user use requires lock-down. Continue?(风险告知)

    • Yes
  • Setup mode(选择配置模式)

    • QuickStart
  • Model/auth provider(选择执行模型)

    • Skip for now(暂时跳过)
  • Filter models by provider(选择供应商)

    • All providers
  • Default model (默认模型)

    • Keep current

验证:全部显示✅即表示配置成功。

启动向导

  • 1.运行诊断命令 pnpm openclaw doctor

    • 依次提示“是否创建token”、“是否创建.openclaw文件夹”等,均选择Yes
    • 完成后,会在C:\Users\${userName}\里创建.openclaw文件夹
  • 2.配置本地网关 openclaw config set gateway.mode local

  • 3.启动本地网关 openclaw gateway

  • 4.在浏览器打开(默认http://127.0.0.1:18789

验证:可在浏览器打开初始化连接界面

相关配置

  • 配置文件位置:C:\Users\${userName}\openclaw.json
  • 如已一键安装过OpenClaw,建议备份整个.openclaw文件夹,并选择性覆盖

token

  • 初始化界面输入token并连接,然后在控制-概览里配置网关令牌

模型

// openclaw.json
{
  // ...,
  "models": {
    "providers": {
      "DeepSeek": {
        "baseUrl": "xxx", // 替换即可
        "apiKey": "xxx", // 替换即可
        "api": "openai-completions",
        "models": [
          {
            "id": "xx", // 替换即可
            "name": "DeepSeek-V3.2 (非思考模式)",
            "reasoning": false,
            "input": ["text"],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 128000,
            "maxTokens": 8192
          }
        ]
      }
    }
  }
}