本文译自 openai/codex 仓库 docs/install.md(commit 4517871),原文:docs/install.md @ 4517871;许可:Apache License 2.0;修改说明:翻译为中文并调整排版。

安装与构建

系统要求

要求说明
操作系统macOS 12+、Ubuntu 20.04+/Debian 10+,或通过 WSL2 使用 Windows 11
Git(可选,推荐)2.23+,用于内置的 PR 辅助功能
内存最低 4 GB(推荐 8 GB)

DotSlash

GitHub Release 中还包含一个名为 codex 的 DotSlash 文件,供 Codex CLI 使用。使用 DotSlash 文件可以向版本控制提交一个轻量条目,从而确保所有贡献者使用同一版本的可执行文件,而不受各自开发平台的影响。

从源码构建

# Clone the repository and navigate to the root of the Cargo workspace.
git clone https://github.com/openai/codex.git
cd codex/codex-rs

# Install the Rust toolchain, if necessary.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
rustup component add rustfmt
rustup component add clippy
# Install helper tools used by the workspace justfile:
cargo install --locked just
# DotSlash fetches pinned development tools such as buildifier on first use.
cargo install --locked dotslash
# Install nextest for the `just test` helper.
cargo install --locked cargo-nextest

# Build Codex.
cargo build

# Launch the TUI with a sample prompt.
cargo run --bin codex -- "explain this codebase to me"

# After making changes, use the root justfile helpers (they default to codex-rs):
just fmt
just fix -p <crate-you-touched>

# Run the relevant tests (project-specific is fastest), for example:
just test -p codex-tui
# `just test` runs the test suite via nextest:
just test
# Avoid `--all-features` for routine local runs because it increases build
# time and `target/` disk usage by compiling additional feature combinations.

跟踪 / 详细日志

Codex 使用 Rust 编写,因此会读取 RUST_LOG 环境变量来配置日志行为。

TUI 默认将诊断信息记录到有大小上限的本地存储中。显式设置 log_dir 可以为一次运行启用纯文本 TUI 日志:

codex -c log_dir=./.codex-log
tail -F ./.codex-log/codex-tui.log

非交互模式(codex exec)默认使用 RUST_LOG=error,但消息会直接打印出来,因此无需监控单独的文件。

有关配置选项的更多信息,请参阅 Rust 文档中关于 RUST_LOG 的说明。