Node.js + npm(PATH 安装完整性检查)
OpenClaw 的运行时基线要求为 Node 22+。 如果你能运行npm install -g openclaw@latest,但之后看到 openclaw: command not found,这几乎总是 PATH 问题:npm 存放全局二进制文件的目录不在你 shell 的 PATH 中。
快速诊断
运行:$(npm prefix -g)/bin(macOS/Linux)或 $(npm prefix -g)(Windows)未出现在 echo "$PATH" 的输出中,你的 shell 就无法找到全局 npm 二进制文件(包括 openclaw)。
修复:将 npm 的全局 bin 目录添加到 PATH
- 查找你的全局 npm 前缀:
- 将全局 npm bin 目录添加到你的 shell 启动文件中:
- zsh:
~/.zshrc - bash:
~/.bashrc
npm prefix -g 输出):
rehash / 在 bash 中运行 hash -r)。
在 Windows 上,将 npm prefix -g 的输出添加到你的 PATH 中。
修复:避免 sudo npm install -g / 权限错误(Linux)
如果 npm install -g ... 因 EACCES 失败,请将 npm 的全局前缀切换到用户可写的目录:
export PATH=... 这一行持久化到你的 shell 启动文件中。
推荐的 Node 安装方式
如果 Node/npm 的安装方式满足以下条件,你将遇到最少的问题:- 保持 Node 更新(22+)
- 使全局 npm bin 目录稳定且在新 shell 中位于 PATH 中
- macOS:Homebrew(
brew install node)或版本管理器 - Linux:你偏好的版本管理器,或提供 Node 22+ 的发行版支持的安装方式
- Windows:官方 Node 安装程序、
winget或 Windows Node 版本管理器