openclaw + ollama 本地源码安装
openclaw 本地源码安装

openclaw + ollama 本地源码安装



本文采用源码安装openclaw,并结合ollama本地运行大模型的方式,运行openclaw。本文安装的版本为OpenClaw 2026.3.13。

克隆代码

访问github,获取clone链接,直接clone代码。

链接:https://github.com/openclaw/openclaw

git clone https://github.com/openclaw/openclaw 

安装依赖

首先安装node,官方推荐 Node 24 (recommended) or Node 22.16+,然后安装pnpm

#安装pnpm 
npm install -g pnpm

#安装openclaw依赖
cd openclaw

pnpm install

安装openclaw

pnpm ui:build # auto-installs UI deps on first run
pnpm build

以下是详细配置步骤

1、配置 openclaw

以下步骤中出现选择的,都是按上下键切换选项,按空格键选中

# pnpm openclaw onboard --install-daemon

 I understand this is personal-by-default and shared/multi-user use requires lock-down. Continue?
│  ● Yes / ○ No   # 选择yes

◆  Onboarding mode
│  QuickStart     # 选择QuickStart

◆  Model/auth provider
│ ○ Cloudflare AI Gateway
│ ● Custom Provider    # 所有的兼容openai的都可以选这个包括ollama
◆  API Base URL
│  http://127.0.0.1:11434/v1   #注意此处没有带/v1的话需要手动填写上
◆  How do you want to provide this API key?
│  ● Paste API key now   # ollama 默认没有认证 所以直接选这个然后随便填写几个字母就行
◆  API Key (leave blank if not required)
│  ollama█               # 我直接填写ollama
◆  Endpoint compatibility
│  ● OpenAI-compatible (Uses /chat/completions)  # 直接选openai兼容接口
│  ○ Anthropic-compatible
│  ○ Unknown (detect automatically)
◆  Model ID
│  qwen/qwen3-4b-thinking-2507          # 直接填写你想使用的模型
◇  Verification successful.
│
◇  Endpoint ID
│  custom-127-0-0-1-12345    # 可以不修改 
│
◇  Model alias (optional)
│  qwen3-4b-thinking-2507    # 可以随便写,注意: 这一步写完之后,不要操作,稍等一下
Configured custom provider: custom-127-0-0-1-12345/qwen/qwen3-4b-thinking-2507
◆  Select channel (QuickStart)
│  ● Telegram (Bot API) (recommended · newcomer-friendly)
│  ○ Skip for now            # 配置channel 需要的话直接选择填写,没有的话直接Skip for now
◇  Web search ────────────────────────────────────────╮
│                                                     │
│  Web search lets your agent look things up online.  │
│  Choose a provider and paste your API key.          │
│  Docs: https://docs.openclaw.ai/tools/web           │
│                                                     │
├─────────────────────────────────────────────────────╯
│
◆  Search provider
│  ● Brave Search (Structured results · country/language/time filters)
│  ○ Gemini (Google Search)
│  ○ Grok (xAI)
│  ○ Kimi (Moonshot)
│  ○ Perplexity Search
│  ○ Skip for now   # 需要的话直接选择填写,没有的话直接Skip for now
◇  Skills status ─────────────╮
│                             │
│  Eligible: 4                │
│  Missing requirements: 39   │
│  Unsupported on this OS: 8  │
│  Blocked by allowlist: 0    │
│                             │
├─────────────────────────────╯
│
◆  Configure skills now? (recommended)
│  ● Yes / ○ No                 # 选择 yes
◆  Install missing skill dependencies
│  ◻ Skip for now (Continue without installing dependencies)  #需要的话直接选择填写,没有的话直接Skip for now
◇  Set NOTION_API_KEY for notion?
│  No                                 # 以下几个都选择No
◇  Set NOTION_API_KEY for notion?
│
◇  Set OPENAI_API_KEY for openai-image-gen?
│  No
│
◇  Set OPENAI_API_KEY for openai-whisper-api?
│  No
│
◇  Set ELEVENLABS_API_KEY for sag?
│  No
│
◇  Hooks ──────────────────────────────────────────────────────────────────╮
│                                                                          │
│  Hooks let you automate actions when agent commands are issued.          │
│  Example: Save session context to memory when you issue /new or /reset.  │
│                                                                          │
│  Learn more: https://docs.openclaw.ai/automation/hooks                   │
│                                                                          │
├──────────────────────────────────────────────────────────────────────────╯
│
◆  Enable hooks?
│  ◻ Skip for now                #需要的话直接选择填写,没有的话直接Skip for now
│  ◻ 🚀 boot-md
│  ◻ 📎 bootstrap-extra-files
│  ◻ 📝 command-logger
│  ◻ 💾 session-memory
◇  Gateway service runtime ────────────────────────────────────────────╮
│                                                                      │
│  QuickStart uses Node for the Gateway service (stable + supported).  │
│                                                                      │
├──────────────────────────────────────────────────────────────────────╯

2、运行网关

上面配置就结束了,下面另起一个命令窗口

# 运行gateway
pnpm gateway:watch

# 这时候打开浏览器访问 http://localhost:18789 

自此openclaw安装完成

实用技巧

如果需要访问令牌执行以下命令

pnpm openclaw dashboard --no-open

如果想要改变端口,执行以下命令

pnpm openclaw gateway --port 1878

如果出现以下告警,原因是ollama的上下文长度太小了,需要修改默认的上下文长度

 [agent/embedded] low context window: custom-127-0-0-1-12345/qwen/qwen3-4b-thinking-2507 ctx=16000 (warn<32000) source=modelsConfig  

 # 当你修改完之后,还会出现这个告警,这时候需要你修改openclaw.json的模型配置参数,将contextWindow,修改成正确的值

   "models": {
    "mode": "merge",
    "providers": {
      "custom-127-0-0-1-12345": {
        "baseUrl": "http://127.0.0.1:12345",
        "apiKey": "ollama",
        "api": "openai-completions",
        "models": [
          {
            "id": "qwen/qwen3-4b-thinking-2507",
            "name": "qwen/qwen3-4b-thinking-2507 (Custom Provider)",
            "reasoning": false,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 64000,
            "maxTokens": 4096
          }
        ]
      }
    }