Codex CLI is OpenAI’s open-source coding agent for the terminal. It reads your code, proposes and makes changes, and runs commands inside a sandbox so it can’t touch files outside your project without permission. You can sign in with a ChatGPT plan or use an OpenAI API key.
This guide covers installing Codex CLI on Linux with npm or the standalone installer, signing in, running tasks interactively and from scripts, and configuring it.
Requirements
- A 64-bit x86 or ARM64 Linux system (Ubuntu, Debian, Fedora, RHEL family, Arch) or WSL2.
- For the npm method: Node.js 22 or newer.
- A ChatGPT plan that includes Codex (such as Plus, Pro, Business, Edu or Enterprise) or an OpenAI API key.
- Git, so you can review and undo the changes Codex makes.
Method 1: Install Codex CLI with npm
Check your Node.js version first:
node --version
If it is older than v22, or Node.js isn’t installed, install Node.js with NVM and install the current LTS release. Then install Codex globally:
npm install -g @openai/codexcodex --version
Method 2: Install Codex CLI with the Standalone Installer
OpenAI also offers an install script that downloads a prebuilt binary and needs no Node.js:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
Running the same command again updates Codex. As with any script piped to a shell, check that the URL matches the one in the official Codex repository before running it.
Sign In
Start Codex in a project folder:
cd ~/myprojectcodex
Choose Sign in with ChatGPT to use your ChatGPT plan; a browser window opens to approve it. To use an API key instead, which is often easier on a headless server, pass the key through standard input so it doesn’t end up in your shell history:
export OPENAI_API_KEY=sk-...printenv OPENAI_API_KEY | codex login --with-api-key
Run Tasks
At the Codex prompt, describe what you want, for example add a –dry-run option to backup.sh. Codex shows its plan, the commands it wants to run and a diff of each file change. Commands run in a sandbox; when Codex needs more access, such as the network or files outside the project, it asks first.
For automation, codex exec runs a single task without the interactive interface:
codex exec 'Find every TODO in this repository and list them with file and line number'
Configure Codex
- AGENTS.md: put a file with this name in your repository to tell Codex how the project is built, tested and styled. Codex reads it automatically.
- ~/.codex/config.toml: your personal settings, such as the default model and MCP servers.
For example, this adds the official fetch MCP server to ~/.codex/config.toml:
[mcp_servers.fetch]
command = "uvx"
args = ["mcp-server-fetch"]
More servers are listed in the best MCP servers for developers and sysadmins.
Update and Uninstall
npm install:
npm install -g @openai/codex@latestnpm uninstall -g @openai/codex
Standalone install: run the install script again to update. Your login and settings are in ~/.codex; delete that folder to remove them.
Conclusion
Codex CLI is now installed and ready to use. Work inside a Git repository so you can review every change with git diff, and keep an AGENTS.md file up to date. See how it compares with Anthropic’s and Google’s agents in Claude Code vs Codex CLI vs Antigravity CLI.
How did it make you feel?
