跳到主要内容

安装 Node.js

Claude Code、Codex、Gemini CLI 都需要 Node.js 运行环境。根据你的操作系统选择对应的安装方式。


Windows

方法一:官方安装包(推荐)

  1. 访问 https://nodejs.org
  2. 下载 LTS 版本的 Windows Installer(.msi 文件)
  3. 运行安装程序,按默认设置点击下一步完成安装

验证安装

打开命令提示符或 PowerShell,运行:

node --version
npm --version

两行都输出版本号即为安装成功。

方法二:使用 Chocolatey

如果你已安装 Chocolatey,以管理员身份运行 PowerShell:

choco install nodejs
node --version
npm --version

macOS

使用 Homebrew 安装(推荐)

brew install node

还没有安装 Homebrew?请先参考 安装 Homebrew

安装完成后验证:

node --version
npm --version

方法二:官网下载

  1. 访问 https://nodejs.org
  2. 下载 LTS 版本的 .pkg 安装包
  3. 双击安装包按提示完成安装

安装完成后,打开终端验证:

node --version
npm --version

Linux

Ubuntu / Debian

sudo apt update
sudo apt install -y nodejs npm
node --version
npm --version

CentOS / RHEL

sudo yum update
sudo yum install -y nodejs npm
node --version
npm --version

Fedora

sudo dnf install -y nodejs npm
node --version
npm --version

使用 NodeSource 仓库(推荐,获取最新 LTS 版本)

适用于 Ubuntu/Debian 系统,可安装比系统仓库更新的 Node.js 版本:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
node --version
npm --version