1. 下载 Node.js LTS
打开 Node.js 官方下载页,选择当前 LTS 版本和与你的 CPU 架构匹配的安装方式。
- 下载 Windows 安装包并按向导安装,保留 npm 与 PATH 选项。
- 关闭原终端,重新打开 PowerShell。
- 执行 node --version 和 npm.cmd --version,确认都能输出版本。
- 从官网下载适合 Intel / Apple Silicon 的安装包,或使用你已有的 Node.js 版本管理器。
- 安装完成后重新打开 Terminal。
- 执行 node --version 和 npm --version 检查。
- 使用 Node.js 官方页面针对发行版推荐的安装方式,或已有的版本管理器安装当前 LTS。
- 重新打开 Shell,确认 PATH 指向预期 Node.js。
- 执行 node --version 和 npm --version。
Node.js 与 npm
Codex 的 npm 安装方式需要 Node.js。请从 Node.js 官网 安装当前 LTS 版本,重新打开终端后检查:
Shell
node --version
npm --versionClaude Code 可使用官方原生安装器,不一定需要 Node.js。若采用 npm 安装方式,也需要 Node.js。
Windows / macOS / Linux
Windows 使用 PowerShell。若 npm.ps1 因执行策略被阻止,可先使用 npm.cmd;不需要为安装工具关闭系统保护。Claude Code 在 Windows 上可能需要 Git for Windows / Git Bash,请以安装提示为准。
PowerShell
npm.cmd install -g @openai/codex@latest
codex --versionmacOS 可通过 Node.js 官网安装 LTS,或使用自己熟悉的版本管理器。不要混用多套 Node.js 导致命令路径冲突。
Shell
npm install -g @openai/codex@latest
codex --versionLinux 建议用版本管理器安装用户级 Node.js,避免全局安装目录的权限问题。
Shell
npm install -g @openai/codex@latest
codex --version默认配置目录
| 工具 | Windows | macOS / Linux | 覆盖变量 |
|---|---|---|---|
| Codex | %USERPROFILE%\.codex | ~/.codex | CODEX_HOME |
| Claude Code | %USERPROFILE%\.claude | ~/.claude | CLAUDE_CONFIG_DIR |