🖥️ 拼车 / 独享套餐均支持 Claude 桌面端 · Chat / Cowork / Design / Science 全功能可用

Codex 安装教程:从下载安装到首次运行

更新于 2026-10-23 · reclaude.cyou

简答:想安装 Codex,先确认你要的是终端 CLI、桌面应用还是 IDE 扩展。CLI 可用官方脚本、npm 或 Homebrew 安装;完成后运行 codex,再按提示使用 ChatGPT 登录或 API Key 登录。

定义:Codex CLI 是运行在本地终端中的编程代理工具,可在项目目录中读取代码、提出修改、执行经批准的命令,并通过交互式终端完成开发任务。

先选对 Codex 形态:CLI、桌面应用还是 IDE 扩展?

“Codex 安装”并不只有一个入口。若你习惯终端、希望在项目目录中直接检查和修改代码,选择 Codex CLI;若你更喜欢图形界面,可使用桌面应用;若主要在编辑器内工作,可安装 IDE 扩展。云端入口则不需要在本机安装 CLI。

使用场景更合适的入口是否需要执行终端安装命令
在终端进入项目并执行任务Codex CLI需要
希望使用图形界面管理项目桌面应用通常不需要单独安装 CLI
在编辑器中边写代码边调用IDE 扩展按对应编辑器入口安装
不想配置本机环境云端入口不需要本地 CLI

本文重点讲 Codex CLI 的安装、登录和首次运行。Codex CLI 的官方入口、桌面应用、IDE 和云端形态可在 Codex 官方代码仓库说明中交叉确认;命令行安装与首次运行步骤以 Codex CLI 官方文档为准。

macOS 与 Linux:优先使用官方独立安装脚本

在 macOS 或 Linux 终端中,官方文档提供独立安装脚本。打开终端后执行:

curl -fsSL https://chatgpt.com/codex/install.sh | sh

安装完成后,先验证命令是否可用:

codex --version

如果终端提示找不到命令,先关闭并重新打开终端,再检查当前用户的可执行文件目录是否已经加入 PATH。不要把版本号写死在文章或脚本中,安装脚本会按当前官方发布逻辑处理版本。

使用 Homebrew 安装

如果你已经在使用 Homebrew,也可以执行:

brew install --cask codex

后续用以下命令确认:

codex --version

官方文档同时列出了独立脚本、npm 和 Homebrew 入口。选择一种方式即可,不建议在同一台机器上重复安装多个来源,否则 PATH 顺序可能让你运行到并非预期的 Codex。

若要升级,优先重新执行官方独立安装脚本,或使用官方文档列出的更新命令;升级后再次执行 codex --version 检查命令是否仍可用。

Windows:PowerShell 安装、验证与 WSL2 选择

Windows 用户可以在 PowerShell 中使用官方独立安装命令:

powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

完成后重新打开 PowerShell,并验证:

codex --version

如果 PowerShell 报执行策略、PATH 或命令不存在,按下面顺序排查:

  1. 关闭当前 PowerShell,重新打开一个窗口,再运行 codex --version。

  2. 确认安装命令完整执行,没有被代理、权限或安全软件中断。

  3. 如果仍然无法识别命令,检查官方安装目录是否已加入当前用户 PATH;不要直接把密钥或登录缓存写入脚本。

  4. 如果你更习惯 Linux 工具链,或者本地环境对 Windows 沙箱、权限和命令兼容性不理想,可以考虑 Windows 11 下的 WSL2。官方安装资料把 WSL2 列为 Windows 使用 Codex 的一种环境路径,但是否需要切换应以你的项目依赖和本机环境为准。

如果你使用 npm 管理开发工具,也可以选择 npm 安装方式;但 Windows 上遇到 npm 全局目录未加入 PATH、脚本权限或平台包解析问题时,先回到官方 PowerShell 独立安装路径排查,避免同时保留多个 Codex 安装。

npm 安装:适合已经配置 Node.js 的用户

官方资料提供 npm 安装方式:

npm install -g @openai/codex

安装后执行:

codex --version

npm 方式适合已经在使用 Node.js 和 npm 的开发者。它的优点是可以沿用现有的全局包管理习惯;缺点是命令是否可用还取决于 npm 全局 bin 目录是否在 PATH 中。

npm 安装后找不到 codex

  1. 先运行 npm prefix -g,确认全局安装位置。

  2. 检查该目录对应的可执行文件目录是否在 PATH 中。

  3. 重新打开终端,再运行 codex --version。

  4. 如果仍失败,不要盲目重复安装;可改用官方独立安装脚本,并在安装后只保留一个优先命令来源。

如果你需要固定企业环境中的版本,应以组织内部审核后的版本和官方部署文档为准。本文不提供未经核验的第三方二进制地址、镜像地址或模型 ID。

首次运行:进入项目、登录并完成第一条任务

安装成功不等于已经完成登录。先进入要处理的项目目录,例如:

cd /path/to/your-project

Windows PowerShell 可使用:

cd C:\path\to\your-project

然后启动:

codex

首次运行时,按界面提示选择 ChatGPT 登录或其他可用认证方式。官方认证文档说明,Codex CLI 也支持 API Key 或访问令牌等登录路径;如果使用 API Key,不要把完整密钥粘贴到公开仓库、工单或聊天记录中。需要检查登录状态时,可使用:

codex login status

进入交互界面后,建议先用低风险任务验证项目路径和权限,例如“说明这个项目的目录结构,不要修改文件”。确认目录正确、权限模式符合预期后,再提出具体修改要求。Codex CLI 的命令、登录方式和权限选项会随版本变化,遇到命令差异时,优先查看 官方 CLI 命令参考。

如果你更喜欢 API Key 登录,官方帮助文档提供了 codex login --with-api-key 的认证路径;不要在 shell 历史、截图或代码仓库中暴露密钥内容。相关登录说明可参考 官方 Codex 登录帮助。

升级、重新登录与卸载怎么做?

升级

优先使用与你安装方式对应的官方更新方式。独立安装脚本可以重新执行;npm 安装可再次执行:

npm install -g @openai/codex

部分版本也支持:

codex update

升级后用 codex --version 验证。若命令参考显示当前版本不支持某个更新子命令,就继续使用原安装方式更新。

重新登录

登录状态异常时,可先查看:

codex login status

需要切换账号或清理本地凭据时,使用:

codex logout

然后重新执行 codex login。认证缓存属于敏感信息,不应提交到 Git,也不应复制给他人。

卸载

如果通过 npm 安装,可使用:

npm uninstall -g @openai/codex

如果通过 Homebrew 安装,可使用:

brew uninstall --cask codex

独立安装方式的卸载路径可能随安装器版本变化,建议先查看官方安装文档或安装脚本说明,再删除对应文件,避免只删除命令入口而留下旧文件。

Codex 安装失败:按现象定位

现象优先检查处理方式
codex 找不到PATH、终端是否重启、是否存在多个安装来源重新打开终端,检查安装目录,必要时只保留一种安装方式
PowerShell 无法执行安装脚本命令是否完整、执行策略、网络请求是否被拦截在新的 PowerShell 窗口重试,并核对官方命令
登录失败浏览器登录是否完成、账号认证方式是否正确运行 codex logout 后重新 codex login
启动后目录不对当前工作目录先用 cd 进入项目根目录,再启动 codex
Windows 环境权限或沙箱不兼容本机项目依赖和运行环境考虑使用 Windows 11 的 WSL2,并以官方支持说明为准

排查时不要先更换未核验的下载地址或第三方安装包。先确认系统、安装来源、PATH、登录状态和当前项目目录,这五项通常足以定位大多数“安装后不能用”的问题。

常见问题

Codex CLI 安装后为什么提示找不到命令?

最常见原因是安装目录没有进入 PATH,或终端尚未重新加载环境变量。先关闭并重新打开终端,再运行 codex --version;如果仍失败,检查 npm 全局目录或独立安装器使用的命令目录,并避免多个安装来源互相覆盖。

Windows 应该直接安装还是使用 WSL2?

如果你主要使用 PowerShell 和 Windows 工具链,可先尝试官方 PowerShell 安装方式;如果项目依赖 Linux 工具链,或遇到权限、沙箱和命令兼容性问题,再考虑 Windows 11 的 WSL2。选择应以项目环境和官方支持说明为准。

Codex CLI 首次运行必须使用 API Key 吗?

不一定。首次运行时可以按界面选择 ChatGPT 登录或其他可用认证方式;官方认证文档也提供 API Key 和访问令牌路径。无论使用哪种方式,都不要公开保存完整凭据。

npm、Homebrew 和独立脚本能同时安装吗?

不建议这样做。多个来源可能把不同版本放在不同目录,最终由 PATH 顺序决定实际运行哪个 codex。先选择一种方式安装和升级,遇到命令冲突时先检查命令路径与版本。

如何确认 Codex 已经登录?

运行 codex login status。若状态异常,可先运行 codex logout,再重新执行 codex login,并按提示完成认证。

相关阅读

参考资料

  1. Codex CLI|ChatGPT Learn 官方文档(learn.chatgpt.com)
  2. openai/codex|官方 GitHub 仓库与安装说明
  3. Codex CLI 命令行参考|ChatGPT Learn 官方文档(learn.chatgpt.com)
  4. Codex CLI 与 ChatGPT 登录|OpenAI 帮助中心
  5. Codex 认证方式与凭据安全|ChatGPT Learn 官方文档(learn.chatgpt.com)

What is ReClaude and who might use it?

ReClaude is described as an account-management service for Claude Code and related Claude clients. Its listed options include two-person shared access and private plans, with support mentioned for Claude Code, Desktop, Chat, Cowork, Design, and Science. The service says it assigns accounts, tracks usage, and handles account replacement during the subscription period. It may interest developers who want subscription-based access without manually changing account settings, but plan availability and service terms should be checked before purchase.

How to get started and choose a plan

The listed process has three stages: install the ReClaude client, authorize an account in the browser, and let the client complete device registration and configuration. The page says Claude Code can then be used without changing its configuration files or adding environment variables. Shared access is described as two people using one Max 5x account with an individual half-share, while private 5x and 20x options are presented for users who prefer exclusive access. Confirm current plans and supported systems before subscribing.

What to verify before using it

Before getting started, review the current service notice, supported operating systems, replacement rules, and any limits that may apply to your selected plan. The page states that Linux is prioritized, Windows follows, and macOS is still being developed. Avoid reusing important passwords, protect browser authorization details, and check what account data the client can access. Also consider whether shared or managed account access fits your organization’s policies, contractual obligations, and acceptable-use requirements.

FAQ

Which tools can ReClaude be used with?

The page presents Claude Code as the main use case and also mentions Claude Desktop, Chat, Cowork, Design, Science, Cursor, and other clients compatible with Anthropic API workflows. Compatibility may change, so check the latest service notice before setup.

How does the shared plan allocation work?

The listed two-person shared option uses one Max 5x account, with each participant described as receiving half of the available subscription allocation. Confirm the current participant limit, usage rules, and plan details before ordering.

What happens if an assigned account is blocked?

The service describes automatic account replacement during the subscription period when a block is detected. For the private 20x plan, the page lists two 20x replacements per subscription cycle before switching to private 5x; verify current terms in the service notice.

This page is a third-party introduction to ReClaude and is not affiliated with ReClaude; refer to ReClaude’s announcements for the latest details.