# Node.js

> 为 OpenClaw 安装和配置 Node.js——版本要求、安装选项和 PATH 故障排查

- 网址：https://funcoding.ai/agents/openclaw/install/node/
- 来源：OpenClaw 官方文档原文（中文），MIT 许可，同步于 2026-10-11
- 官方原文：https://docs.openclaw.ai/zh-CN/install/node

---
OpenClaw 要求使用 **Node 22.22.3+、Node 24.15+ 或 Node 25.9+**。**Node 24 是安装、CI 和发布工作流的默认及推荐运行时**；Node 22 仍通过活跃的 LTS 版本线获得支持。不支持 Node 23。[安装脚本](https://funcoding.ai/agents/openclaw/install/#alternative-install-methods)会自动检测并安装 Node——如果你想自行设置 Node（版本、PATH、全局安装），请使用本页面。

## 检查版本

```bash
node -v
```

推荐默认使用 `v24.15.0` 或更新的 24.x 版本。`v22.22.3` 或更新的 22.x 版本是受支持的 Node 22 LTS 路径；Node `v25.9.0+` 也受支持。不支持 Node 23。如果未安装 Node 或其版本不在支持范围内，请选择下方的一种安装方式。

## 安装 Node

**macOS**

**Homebrew**（推荐）：

```bash
brew install node
```

或从 [nodejs.org](https://nodejs.org/) 下载 macOS 安装程序。

**Linux**

**Ubuntu / Debian：**

```bash
curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
sudo apt-get install -y nodejs
```

**Fedora / RHEL：**

```bash
sudo dnf install nodejs
```

或使用版本管理器（见下文）。

**Windows**

**winget**（推荐）：

```powershell
winget install OpenJS.NodeJS.LTS
```

**Chocolatey：**

```powershell
choco install nodejs-lts
```

或从 [nodejs.org](https://nodejs.org/) 下载 Windows 安装程序。

<details>
<summary>使用版本管理器（nvm、fnm、mise、asdf）</summary>

  版本管理器可让你轻松切换 Node 版本。常用选项：

- [**fnm**](https://github.com/Schniz/fnm) - 快速、跨平台
- [**nvm**](https://github.com/nvm-sh/nvm) - 在 macOS/Linux 上广泛使用
- [**mise**](https://mise.jdx.dev/) - 多语言版本管理器（Node、Python、Ruby 等）

使用 fnm 的示例：

```bash
fnm install 24
fnm use 24
```

<div class="callout callout-warning">

请在 shell 启动文件（`~/.zshrc` 或 `~/.bashrc`）中初始化版本管理器。如果跳过此步骤，由于 PATH 中未包含 Node 的 bin 目录，在新的终端会话中可能找不到 `openclaw`。

</div>

</details>

## 故障排查

### `openclaw: command not found`

这几乎总是意味着 npm 的全局 bin 目录不在 PATH 中。

**查找 npm 的全局前缀**

```bash
npm prefix -g
```

**检查它是否在 PATH 中**

```bash
echo "$PATH"
```

在输出中查找 `<npm-prefix>/bin`（macOS/Linux）或 `<npm-prefix>`（Windows）。

**将其添加到 shell 启动文件**

**macOS / Linux**

添加到 `~/.zshrc` 或 `~/.bashrc`：

```bash
export PATH="$(npm prefix -g)/bin:$PATH"
```

然后打开一个新终端（或在 zsh 中运行 `rehash`，在 bash 中运行 `hash -r`）。

**Windows**

通过 Settings → System → Environment Variables，将 `npm prefix -g` 的输出添加到系统 PATH。

### `npm install -g` 的权限错误（Linux）

如果看到 `EACCES` 错误，请将 npm 的全局前缀切换到用户可写目录：

```bash
mkdir -p "$HOME/.npm-global"
npm config set prefix "$HOME/.npm-global"
export PATH="$HOME/.npm-global/bin:$PATH"
```

将 `export PATH=...` 这一行添加到 `~/.bashrc` 或 `~/.zshrc`，使其永久生效。

## 相关内容

- [安装概览](https://funcoding.ai/agents/openclaw/install/) - 所有安装方式
- [更新](https://funcoding.ai/agents/openclaw/install/updating/) - 使 OpenClaw 保持最新
- [入门指南](https://funcoding.ai/agents/openclaw/start/getting-started/) - 安装后的初始步骤
