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 st始终运行最新版本(22+)
- 使全局 npm 的 bin 目录保持稳定,并在新 shell 中自动添加到 PATH 中。
- macOS:Homebrew(
brew install node)或版本管理器 - Linux:您偏好的版本管理器,或由发行版支持且提供 Node 22+ 安装方式的工具
- Windows:官方 Node 安装程序、
winget,或适用于 Windows 的 Node 版本管理器