Codex Installation and Usage |
\n\nCodex can be used in multiple ways. Depending on developersβ preferences, there are roughly five installation methods:
\n\n| Installation Method | \nUsage Scenario | \nRecommendation | \n
|---|---|---|
| Codex App | \nDownload and use the Codex app directly | \nββββ | \n
| Codex CLI | \nUse in terminal | \nβββββ | \n
| IDE Plugin | \nUse in VS Code / Cursor | \nββββ | \n
| Homebrew Installation | \nMac users | \nββββ | \n
| GitHub Release Binary | \nManual installation | \nβββ | \n
The following sections introduce each method in detail.
\n\n\n\n
1. Codex App
\n\nThe simplest way is to directly use the Codex app, which requires a good network connection.
\n\nVisit: https://chatgpt.com/codex
\n\nDownload the app:
\n\nLog in with your ChatGPT account to start using it.
\n\nInterface overview:
\n\nThen, enter your request in the input box:
\n\n\n\n\nIf you encounter issues accessing or using Codex, similar products in China include Alibabaβs Qwen Quest and ByteDanceβs Trae Solo.
\n\n
AI Development Environment
\n\n
2. Codex CLI
\n\nThe most common method for developers is to use Codex CLI.
\n\nCLI is an AI programming agent that runs in the terminal and can:
\n\n- \n
- Read code \n
- Modify code \n
- Execute shell commands \n
- Automatically fix bugs \n
Codex CLI runs locally, so your code is not uploaded to the cloud; only the prompt and necessary context are sent to the model.
\n\n\n\n
Installing Codex CLI
\n\nInstall using npm:
\n\nsudo npm install -g @openai/codex\n# Install faster using a domestic mirror\nsudo npm install -g @openai/codex --registry=https://registry.npmmirror.com\n\nAfter installation, run:
\n\ncodex\n\nto start Codex.
\n\nLogging into Codex
\n\nThe first run requires login.
\n\nThere are two methods:
\n\nMethod 1: ChatGPT Login (Recommended)
\n\ncodex\n\nSelect:
\n\nSign in with ChatGPT\n\nThen the browser will open the login page. After logging in, you can start using it.
\n\nMethod 2: API Key Login
\n\nFor developers using the developer mode, you can use an API key:
\n\n# macOS / Linux - Temporary setting (valid only for current terminal session)\nexport OPENAI_API_KEY="sk-Your API key"\n# Permanent configuration (add to ~/.bashrc or ~/.zshrc)\necho 'export OPENAI_API_KEY="sk-Your API key"' >> ~/.zshrc\nsource ~/.zshrc\n\n# Windows PowerShell\n$env:OPENAI_API_KEY="sk-Your API key"\n\n# After configuration, start Codex (specify model)\ncodex --model gpt-5-codex\n\nThen run:
\n\ncodex\n\nMethod 3: auth.json Configuration
\n\nManually edit the authentication file. Create the directory:
\n\nmkdir -p ~/.codex\n\nWrite the API key:
\n\ncat > ~/.codex/auth.json << 'EOF'\n{\n "OPENAI_API_KEY": "sk-Your API key"\n}\nEOF\n\nFirst-time Run of Codex
\n\nEnter your project directory:
\n\ncd my-project\n\nStart Codex:
\n\ncodex\n\nThen input:
\n\nAnalyze the current project structure\n\nCodex will automatically:
\n\n- \n
- Scan the codebase \n
- Analyze the project structure \n
- Output system architecture description \n
For example, create a directory:
\n\nmkdir codex-tutorial-test\n\nEnter the directory:
\n\ncd codex-tutorial-test\n\nCreate a new test.py file with the following code:
print("Hello Tutorial!")\n\nStart Codex:
\n\ncodex\n\nSelect the first option Yes, continue and press Enter. Now you can start using Codex CLI to write code:
Three Running Modes of Codex
\n\nCodex CLI provides three security modes:
\n\n| Mode | \nFunctionality | \n
|---|---|
| Suggest | \nSuggests modifications only | \n
| Auto Edit | \nAutomatically modifies files | \n
| Full Auto | \nAutomatically executes all operations | \n
The default mode is:
\n\nSuggest\n\nTo switch modes:
\n\ncodex --auto-edit\n\nor:
\n\ncodex --full-auto\n\nThe Full Auto mode can automatically execute code fixes and tasks.
Updating and Uninstalling
\n\n# Update to the latest version\nnpm update -g @openai/codex\n\n# Or force reinstall the latest version\nnpm install -g @openai/codex@latest\n\n# Uninstall\nnpm uninstall -g @openai/codex\n\n# Homebrew uninstall\nbrew uninstall --cask codex\n\n\n\n
3. Homebrew Installation (Recommended for Mac)
\n\nMac users can install using Homebrew:
\n\nbrew install --cask codex\n\nAfter installation, run:
\n\ncodex\n\nto start Codex.
\n\nThis method is suitable for:
\n\n- \n
- Mac developers \n
- Users who do not want to install Node.js \n
\n\n
GitHub Release Installation (Binary)
\n\nIf you prefer not to use npm, you can download the binary version directly.
\n\nDownload link: https://github.com/openai/codex/releases
\n\nCommon versions:
\n\n- \n
- Mac Apple Silicon:
codex-aarch64-apple-darwin.tar.gz\n - Mac Intel:
codex-x86_64-apple-darwin.tar.gz\n - Linux:
codex-x86_64-unknown-linux-musl.tar.gz\n
After downloading, extract the archive:
\n\ntar -xzf codex-xxx.tar.gz\n\nRename the binary:
\n\nmv codex-x86_64-unknown-linux-musl codex\n\nAdd to PATH:
\n\nsudo mv codex /usr/local/bin\n\nThen run:
\n\ncodex\n\nto start using it.
\n\n\n\n
5. IDE Plugin Installation
\n\nCodex can also be used within IDEs, such as:
\n\n- \n
- VS Code \n
- Cursor \n
- Windsurf \n
- VS Code forks \n
Installation steps:
\n\n- \n
- Open the IDE plugin marketplace \n
- Search for Codex \n
- Install the plugin \n
- Log in with your ChatGPT account \n
Now you can use Codex directly inside your IDE, for example:
\n\n- \n
- Automatically fix code \n
- Automatically generate functions \n
- Automatically refactor code \n
\n\n
6. Updating Codex
\n\nUpdating Codex CLI is very simple:
\n\ncodex --upgrade\n\nor:
\n\nnpm update -g @openai/codex\ncodex --version\n\nCodex CLI currently supports:
\n\n| System | \nSupport Status | \n
|---|---|
| macOS | \nFully supported | \n
| Linux | \nFully supported | \n
| Windows | \nExperimental support (WSL recommended) | \n
YouTip