Skip to main content
__HEADING_0__Node.js + npm(PATH 健康检查) OpenClaw 的运行时基线是 Node 22+ 如果你能够成功运行 npm install -g openclaw@latest,但随后看到 openclaw: command not found,这几乎总是由 PATH 问题引起:npm 将全局二进制文件放置的目录未包含在你的 shell PATH 中。

快速诊断

运行:
node -v
npm -v
npm prefix -g
echo "$PATH"
如果$(npm prefix -g)/bin(macOS/Linux)或$(npm prefix -g)(Windows)未出现在echo "$PATH"中,那么你的 shell 就无法找到全局 npm 二进制文件(包括openclaw)。

解决方案:将 npm 的全局 bin 目录添加到 PATH

  1. 查找你的全局 npm 前缀:
npm prefix -g
  1. 将全局 npm 的 bin 目录添加到你的 shell 启动文件中:
  • zsh:~/.zshrc
  • bash:~/.bashrc
示例(用你的 npm prefix -g 输出替换路径):
# macOS / Linux
export PATH="/path/from/npm/prefix/bin:$PATH"
然后打开一个新终端(或在 zsh 中运行 rehash,或在 bash 中运行 hash -r)。 在 Windows 上,将 npm prefix -g 的输出添加到你的 PATH。

解决方案:避免 sudo npm install -g / 权限错误(Linux)

如果 npm install -g ...EACCES 而失败,请将 npm 的全局前缀切换到用户可写目录:
mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
export PATH="$HOME/.npm-global/bin:$PATH"
export PATH=... 这一行保留在你的 shell 启动文件中。

推荐的 Node 安装选项

为了尽可能减少 Node/npm 安装过程中出现的意外情况,建议采用以下方式:
  • 确保 Node st始终运行最新版本(22+)
  • 使全局 npm 的 bin 目录保持稳定,并在新 shell 中自动添加到 PATH 中。
常见选择:
  • macOS:Homebrew(brew install node)或版本管理器
  • Linux:您偏好的版本管理器,或由发行版支持且提供 Node 22+ 安装方式的工具
  • Windows:官方 Node 安装程序、winget,或适用于 Windows 的 Node 版本管理器
如果你使用版本管理器(nvm、fnm、asdf 等),请确保它已在你日常使用的 shell(zsh 或 bash)中初始化,以便在运行安装程序时,其设置的 PATH 已生效。