Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Codex Installation and Usage

Codex Installation and Usage

Codex can be used in a variety of ways; based on developers' habits, these can be roughly divided into five approaches:

Installation method Use Cases Recommendation
Codex App Download the Codex app directly ⭐⭐⭐⭐
Codex CLI Use in the terminal ⭐⭐⭐⭐⭐
IDE plugin Use in VS Code / Cursor ⭐⭐⭐⭐
Install via Homebrew Mac users ⭐⭐⭐⭐
GitHub Release binary Manual Installation ⭐⭐⭐

The following sections introduce each of them.


1. Codex App

The simplest way is to directly use the Codex app, which requires a good network connection.

to access:https://chatgpt.com/zh-Hans-CN/download/

Download the app:

Log in with your ChatGPT account to use it.

ChatGPT interface description:

Codex mode:

Then you can enter our requirements in the input box:

If there are obstacles to accessing and using Codex, Alibaba's Qoder Quest and ByteDance's Trae Solo in China are similar products.


2、Codex CLI

The most commonly used method among developers is Codex CLI。

The CLI is an AI coding agent that runs in the terminal and can:

Codex CLI runs locally, so code is not uploaded to the cloud; only the prompt and necessary context are sent to the model.


Install Codex CLI

macOS/Linux one-click install and update:



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

Windows one-click install and update:

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

Install and update using npm:

npm install -g @openai/codex



# Use domestic mirror for faster installation

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

After installation, run:

codex

to launch Codex.

Log in to Codex

You need to log in on first run.

There are two ways:

Method 1: ChatGPT Login (Recommended)

codex

Select:

Sign in with ChatGPT

Then the browser will open a login page; once logged in, you can use it.

Method 2: API Key Login

In developer mode, you can use an API Key:

# macOS / Linux - 临时设置(仅当前终端会话有效)

export OPENAI_API_KEY="sk-你的API密钥"



# Permanent configuration (add to ~/.bashrc or ~/.zshrc)

echo 'export OPENAI_API_KEY="sk-你的API密钥"' >> ~/.zshrc

source ~/.zshrc



# Windows PowerShell

$env:OPENAI_API_KEY="sk-你的API密钥"



# Start after configuration (specify model)

codex --model gpt-5-codex

Then run:

codex

Method 3: auth.json File Configuration

Manually edit the authentication file, create a directory:

mkdir -p ~/.codex

Write the API key:

cat > ~/.codex/auth.json << 'EOF'

{

  "OPENAI_API_KEY": "sk-你的API密钥"

}

EOF

First Run of Codex

Enter the project directory:

cd my-project

Start Codex:

codex

Then enter:

分析下当前的项目结构

Codex will automatically:

  1. Scan the codebase
  2. Analyze the project structure
  3. Output a system architecture description

For example, we create a directory:

mkdir codex-runoob-test

Enter the directory:

cd codex-runoob-test

Create a new test.py file with the following code:

print("Hello Runoob!")

Start Codex:

codex

Select the first option, Yes, continue, and press Enter; then you can start using Codex CLI to write code:

Codex's Three Operating Modes

Codex CLI provides three safety modes.

Mode Function
Suggest Suggest edits only
Auto Edit Automatically modify files
Full Auto Automatically execute all actions

Default mode:

Suggest

Switch modes:

codex --auto-edit

or:

codex --full-auto

Full Auto mode can automatically execute code fixes and tasks.

Update and Uninstall

# 更新到最新版本

npm update -g @openai/codex



# or force reinstall latest version

npm install -g @openai/codex@latest



# 卸载

npm uninstall -g @openai/codex



# Homebrew Uninstall

brew uninstall --cask codex


3. Homebrew Installation (Recommended for Mac)

Mac users can install using Homebrew.

brew install --cask codex

After installation, run:

codex

to launch.

This approach is suitable for:


GitHub Release Installation (Binary)

If you do not want to use npm, you can also directly download the binary version.

Download address:https://github.com/openai/codex/releases

Common versions:

Mac Apple Silicon:



codex-aarch64-apple-darwin.tar.gz

Mac Intel:



codex-x86_64-apple-darwin.tar.gz

Linux:



codex-x86_64-unknown-linux-musl.tar.gz

Download and extract:



tar -xzf codex-xxx.tar.gz

Rename:



mv codex-x86_64-unknown-linux-musl codex

Add to PATH:



sudo mv codex /usr/local/bin

Then run:



codex

and it is ready to use.


5. IDE Plugin Installation

Codex can also be used in IDEs, for example:

Installation:

This way you can use Codex directly within the IDE.

For example:


6. Update Codex

Updating Codex CLI is very simple:

codex --upgrade

or:

npm update -g @openai/codex

codex --version

Codex CLI currently supports:

System Support status
macOS Full support
Linux Full support
Windows Experimental support (WSL recommended)