Codex Linux

Codex Linux 使用教程。

当前建议分组:AppCodex 当前建议模型:gpt-5.5

(一) 安装 Node.js 环境

方法一:NodeSource

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

方法二:系统包管理器

1sudo apt update
2sudo apt install nodejs npm

验证安装:

1node --version
2npm --version

(二) 安装 Codex

1npm install -g @openai/codex --registry=https://registry.npmmirror.com

如果你遇到权限问题:

1sudo npm install -g @openai/codex --registry=https://registry.npmmirror.com

验证安装:

1codex --version

(三) 配置 Codex

编辑 ~/.codex/config.toml

 1disable_response_storage = true
 2model = "gpt-5.5"
 3model_reasoning_effort = "high"
 4model_provider = "4router"
 5model_context_window = 1000000
 6model_auto_compact_token_limit = 900000
 7
 8[model_providers.4router]
 9name = "4Router"
10base_url = "https://4router.net/v1"
11requires_openai_auth = true
12wire_api = "responses"

然后编辑 ~/.codex/auth.json,把 Key 写在这里(不再需要 shell 环境变量):

1{
2  "OPENAI_API_KEY": "sk-xxxxx"
3}

如果目录或文件不存在,先创建:

1mkdir -p ~/.codex
2touch ~/.codex/auth.json

(四) 开始使用 Codex

1codex

最小测试示例:

1Print a short hello from the AppCodex group on 4Router.

(五) 常见问题

  • codex 命令不存在:检查 npm 全局安装目录是否在 PATH 中。
  • API 连接失败:检查 ~/.codex/auth.json 是否为合法 JSON,键名是否为 OPENAI_API_KEY
  • 请求失败:先去控制台确认当前令牌能否使用 AppCodex 分组。
  • 模型不可用:把配置里的模型换成你当前账户可用的 Codex 模型。