openclaw - 💡(How to fix) Fix [macOS] Gateway LaunchAgent PATH 缺少 Homebrew 路径,导致启动失败 [4 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fixed

Code Example

function resolveSystemPathDirs(platform) {
    if (platform === "darwin") return [
        "/usr/local/bin",
        "/usr/bin", 
        "/bin",
        "/usr/sbin",
        "/sbin"
    ];
    // ❌ 缺少 /opt/homebrew/bin 和 /opt/homebrew/sbin !
}

---

export PATH='/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'

---

if (platform === "darwin") return [
    "/opt/homebrew/bin",
    "/opt/homebrew/sbin",
    "/usr/local/bin",
    "/usr/bin", 
    "/bin",
    "/usr/sbin",
    "/sbin"
];
RAW_BUFFERClick to expand / collapse

问题描述

在 macOS 上,openclaw gateway restart 会导致 Gateway 服务无法启动,退出码 78 (EX_CONFIG)。

环境

  • macOS (外置磁盘 /Volumes/XYH)
  • Node: v25.9.0 (通过 Homebrew 安装在 /opt/homebrew/bin/node)
  • OpenClaw 版本: 2026.5.7
  • Gateway 端口: 18789

根因分析

查看源码 dist/runtime-paths-DuoLU2TD.js:

function resolveSystemPathDirs(platform) {
    if (platform === "darwin") return [
        "/usr/local/bin",
        "/usr/bin", 
        "/bin",
        "/usr/sbin",
        "/sbin"
    ];
    // ❌ 缺少 /opt/homebrew/bin 和 /opt/homebrew/sbin !
}

问题是:

  1. Gateway 安装时生成的 env 文件中 PATH 不包含 Homebrew 路径
  2. 每次 openclaw gateway restart 都会重新生成 env 文件(基于硬编码的系统路径)
  3. 用户手动修改 PATH 后,restart 又会还原

复现步骤

  1. 安装 OpenClaw: npm install -g openclaw@latest
  2. 安装 Gateway: openclaw gateway install
  3. 手动修改 env 文件添加 /opt/homebrew/bin 到 PATH
  4. 执行 openclaw gateway restart
  5. 查看服务状态: launchctl list | grep openclaw → 退出码 78

预期行为

PATH 应该包含 Homebrew 路径:

export PATH='/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin'

修复建议

修改 resolveSystemPathDirs 函数,在 macOS 返回值中添加 Homebrew 路径:

if (platform === "darwin") return [
    "/opt/homebrew/bin",
    "/opt/homebrew/sbin",
    "/usr/local/bin",
    "/usr/bin", 
    "/bin",
    "/usr/sbin",
    "/sbin"
];

额外说明

这个问题在外置磁盘环境下更明显,因为 launchd 启动时磁盘可能未挂载,导致服务无法找到配置文件。但即使解决挂载问题,PATH 缺失 homebrew 也会导致 node 无法正常启动.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING