Appearance
macOS 安装 Node.js
Claude Code、CodeX 和 Gemini CLI 均需要 Node.js 18+ 版本。
方法一:Homebrew(推荐)
bash
# 安装 Homebrew(如未安装)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# 安装 Node.js LTS
brew install node@22
# 添加到 PATH
echo 'export PATH="/opt/homebrew/opt/node@22/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc方法二:官方安装包
- 访问 https://nodejs.org,下载 macOS LTS 版本
.pkg - 双击运行,按向导完成安装
方法三:nvm(多版本管理,推荐开发者)
bash
# 安装 nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# 重启终端后安装 LTS
nvm install --lts
nvm use --lts验证安装
bash
node -v
npm -v常见问题
Apple Silicon(M 系列芯片)
使用 Homebrew 安装时,路径在 /opt/homebrew/ 而非 /usr/local/,注意 PATH 配置。
npm 速度太慢?
bash
npm config set registry https://registry.npmmirror.com