OpenClaw Mac系统安装、部署、API设置教程全解

Macos小于13,先升级版本号,否则建议云部署

1.Qoder安装

安装 OpenClaw 的时候需要用 Qoder 跑终端命令。如果遇到报错,直接让Qoder帮你解决就行。

如果你已经装了 Qoder,可以跳过这步。

先去官网下载 Qoder: Qoder - The Agentic Coding Platform

遇到问题不用慌,选中终端里的错误信息,直接问Qoder,它会告诉你怎么解决。

下载好之后安装Qoder,拖拽安装

打开Qoder进行安装,选择skip

选择中文

注册/登录Qoder账号

配置中修改界面展示语言及AI回复语言

选择一个文件夹打开,到这一步安装就算结束了

2.OpenClaw安装

打开Qoder,点击右上角这里,会弹出输入框

输入以下命令:

sudo curl -fsSL https://openclaw.ai/install.sh | bash

注意看一下前面带没带sudo,要带,是打开权限

然后有可能会弹出password:

这个是让你输入电脑密码,电脑为了保护你的隐私,输入密码后不会显示,也就是说,按完密码,屏幕上看起来是没变化的,这是正常的,回车即可。

到这里需要等待一段时间,让他下载,慢是正常的,如果卡住就是没有开虚拟网卡模式

当出现终端出现OPENCLAW的时候,就安装完成了。

注意!如果这一步出现问题,那么就跳转这里解决:OpenClaw部署

3.Openclaw设置

方向键选Yes

回车后继续选择QuickStart

选择skip for now:

继续选All providers

继续回车

选Skip for now,继续回车:

选择No

这里需要先空格,然后回车

上下键选择第二个:

回车,安装完成后就会打开网页了,但是此时还不能发起会话:

4.API设置

将以下内容告诉给AI IDE,让它帮你配置API:

选择新建文件

命名为api-configure-skill.md

在里面复制以下内容并粘贴:

# OpenClaw Model Configuration

Interactive guide for configuring OpenClaw models.

## Usage

Users will provide a JSON configuration file in the following format:

```json
{
  "models": {
    "mode": "merge",
    "providers": {
      "bailian": {
        "baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
        "apiKey": "<API_KEY>",
        "api": "openai-completions",
        "models": [
          {
            "id": "<MODEL_ID>",
            "name": "<MODEL_ID>",
            "reasoning": false,
            "input": ["text"],
            "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
            "contextWindow": 128000,
            "maxTokens": 8192
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": { "primary": "bailian/<MODEL_ID>" },
      "models": { "bailian/<MODEL_ID>": {} }
    }
  },
  "gateway": { "mode": "local" }
}
```

## Step 1: Get Configuration

User provides the complete JSON configuration file. If not provided, ask for it.

## Step 2: Write to Both Configuration Files

Write to both paths to ensure configuration consistency:

| File | macOS / Linux | Windows |
|------|---------------|----------|
| models.json | `~/.openclaw/agents/main/agent/models.json` | `%USERPROFILE%\.openclaw\agents\main\agent\models.json` |
| openclaw.json | `~/.openclaw/openclaw.json` | `%USERPROFILE%\.openclaw\openclaw.json` |

### File 1: models.json

Extract the `models.providers` section from user's JSON:

```json
{
  "providers": {
    "bailian": { ... }
  }
}
```

### File 2: openclaw.json

Use the complete JSON configuration provided by user.

## Step 3: Execute Configuration Commands

### macOS / Linux
```bash
# Write models.json
cat > ~/.openclaw/agents/main/agent/models.json << 'EOF'
<extracted providers config>
EOF

# Write openclaw.json
cat > ~/.openclaw/openclaw.json << 'EOF'
<user's complete config>
EOF
```

### Windows (PowerShell)
```powershell
# Write models.json
$modelsJson = @'
<extracted providers config>
'@
$modelsJson | Set-Content "$env:USERPROFILE\.openclaw\agents\main\agent\models.json" -Encoding UTF8

# Write openclaw.json
$openclawJson = @'
<user's complete config>
'@
$openclawJson | Set-Content "$env:USERPROFILE\.openclaw\openclaw.json" -Encoding UTF8
```

## Step 4: Auto-Execute Post-Configuration Tasks (MANDATORY)

**IMPORTANT: After writing configuration files, you MUST automatically execute ALL of the following commands in sequence. Do NOT just display them - actually run them using the terminal.**

### 4.1 Restart Gateway (Required)

Restart the Gateway to apply the new configuration:

**macOS / Linux:**
```bash
openclaw gateway --force --port 18789
```

**Windows (PowerShell):**
```powershell
openclaw gateway --force --port 18789
```

### 4.2 Verify Configuration (Required)

Test the configuration by sending a message:

**macOS / Linux:**
```bash
openclaw agent --session-id main --message "hello"
```

**Windows (PowerShell):**
```powershell
openclaw agent --session-id main --message "hello"
```

### 4.3 Start Dashboard (Required)

Ask the user if they want to open the Dashboard. If yes, execute:

**macOS / Linux:**
```bash
openclaw dashboard
```

**Windows (PowerShell):**
```powershell
openclaw dashboard
```

---

**Reminder:** All commands in Step 4 MUST be executed automatically after configuration. Never skip these steps.

---

## Troubleshooting

### Error: HTTP 401 - Invalid access token or token expired

**Cause:** Incorrect API Key or wrong baseUrl in configuration.

**Solution:**
1. Verify the API Key is correct
2. For Alibaba Cloud Bailian, use the correct endpoint:
   ```
   https://dashscope.aliyuncs.com/compatible-mode/v1
   ```
   NOT `https://coding.dashscope.aliyuncs.com/v1`
3. Ensure both `models.json` and `openclaw.json` have the same API Key

### Error: Dashboard cannot connect / ERR_CONNECTION_REFUSED

**Cause:** Gateway service is not running.

**Solution:**
1. Start the Gateway first:
   ```bash
   openclaw gateway --port 18789
   ```
2. Then open Dashboard:
   ```bash
   openclaw dashboard
   ```

### Error: Configuration changes not taking effect

**Cause:** Gateway needs to be restarted after configuration changes.

**Solution:**
```bash
openclaw gateway --force --port 18789
```

### Error: Model not found / not available

**Cause:** Model ID does not exist in the provider's supported models.

**Solution:**
1. Check available models:
   ```bash
   openclaw models list
   ```
2. Verify the model ID matches the provider's official model name

### Error: WebSocket disconnected / token_missing

**Cause:** Dashboard opened without authentication token.

**Solution:**
1. Use the complete Dashboard URL with token:
   ```bash
   openclaw dashboard
   ```
2. This will open the browser with the correct token in the URL

---

## References

- [OpenClaw Official Documentation](https://docs.openclaw.ai/)
- [OpenClaw Configuration Guide](https://openclawlab.com/en/docs/gateway/configuration/)
- [OpenClaw CLI Reference](https://docs.openclaw.ai/cli/)
- [Models CLI](https://docs.openclaw.ai/cli/models)
- [Configure Command](https://docs.openclaw.ai/cli/configure)
- [OpenClaw GitHub](https://github.com/nicepkg/openclaw)

前往以下表格:API KEY

注意!表格中的API KEY是共享的,为了避免被平台限流、禁用,大家一定要选择未使用的,确认自己要使用这个之后,将下拉框换为已使用:

然后复制其中内容:

再新建一个文件:

命名为api-key.json

在里面粘贴刚刚从在线表格中复制的内容:

点击这里:

选择极致:

输入内容:

参考api-configure-skill.md帮我配置api-key.json中的内容

点击发送:

会帮你自动把api-key配置进去:

配置成功后,即可开始对话:

说真的,有点麻烦,当时折腾了半天

Mac部署教程终于有了

M1和Intel芯片的安装步骤不一样吧

Homebrew装完之后路径要手动加吗

Mac上跑起来比Windows流畅多了

Xcode命令行工具那步别忘了装

Sonoma系统有兼容问题吗?我刚升级

@prism537 M1和Intel的区别主要在Node.js的编译 M1用arm64版本 Intel用x64 nvm会自动识别 不用手动选

@rook27 Homebrew装完一般自动加PATH 如果没生效跑一下eval $(/opt/homebrew/bin/brew shellenv) 然后加到.zshrc里

@hawk502 Xcode命令行工具这步确实容易忘 xcode-select --install 一行命令 不用装完整的Xcode 省十几个G空间