If codex prints zsh: command not found: codex (or bash: codex: command not found) after installing, the shell cannot find the executable. Work through the fix below, then use the rest of this page to install and sign in.
Fix "command not found: codex"
1. Diagnose in 30 seconds
which codex # empty output = not on PATH
npm prefix -g # where npm installs global packages
node --version
npm prefix -g is the current way to find npm's global location. The old npm bin -g command was removed in npm 9 and now fails with Unknown command: "bin".
2. Add npm's global bin folder to PATH
On macOS and Linux npm links global executables into the bin folder under the prefix, so add that folder to your PATH.
# zsh (default on macOS)
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
rehash
# bash
echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
hash -r
codex --version
rehash (zsh) and hash -r (bash) clear the shell's cached command lookups, which can keep reporting "not found" even after PATH is fixed. Opening a new terminal does the same.
On Windows, npm puts the codex shims in the prefix folder itself (no bin subfolder). Run npm prefix -g, add that folder to your user Path under System Properties > Environment Variables, then open a new PowerShell window. If PowerShell says codex is not recognized, this is the cause.
3. Check for a Node version manager
- nvm: global packages live under each Node version, so
npm prefix -gchanges when you switch versions. Runnvm use <version>for the version you installed under, or reinstall withnpm install -g @openai/codexafter switching. - Volta: install with
volta install @openai/codexso Volta creates a shim in its bin folder (~/.volta/bin), which must be on PATH. - asdf: after a global npm install, run
asdf reshim nodejs.
4. Skip the problem: use the standalone installer or Homebrew
OpenAI's install docs list installers that do not depend on npm's prefix:
# macOS / Linux
curl -fsSL https://chatgpt.com/codex/install.sh | sh
# Homebrew
brew install --cask codex
If you installed with Homebrew and which codex is empty, make sure Homebrew's bin folder (/opt/homebrew/bin on Apple Silicon) is on your PATH.
On Ubuntu, if the shell's "command not found" hint suggests installing a codex package from snap or apt, do not assume it is OpenAI's CLI; install using one of the official methods on this page instead.
5. Still stuck?
codex doctor diagnoses the local install, config, and auth. If the directory is already on PATH and the shell still cannot run it, see unable to locate the Codex CLI binary. If a global npm install fails with EACCES, see npm EACCES permission denied when installing Codex and do not re-run it with sudo.
Install methods
OpenAI documents these (Codex CLI docs, GitHub README):
| Method | Install | Update |
|---|---|---|
| macOS/Linux installer | curl -fsSL https://chatgpt.com/codex/install.sh | sh | re-run the same command |
| Windows installer (start from a new PowerShell window) | powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex" | re-run the same command |
| npm | npm install -g @openai/codex | npm install -g @openai/codex |
| Homebrew | brew install --cask codex | brew upgrade --cask codex |
| Release binary | download the archive for your platform from the latest GitHub Release and rename the extracted file to codex | download again |
Verify with:
codex --version
Node.js requirement (npm install only)
Only the npm method needs Node.js and npm. The package's npm metadata declares engines.node as >=16 (npm view @openai/codex engines). The standalone installers and the Homebrew cask do not use npm.
If npm: command not found, install Node.js first: brew install node on macOS, winget install OpenJS.NodeJS.LTS on Windows, or download from nodejs.org. PowerShell words the error differently (npm is not recognized as the name of a cmdlet) and it often persists until you open a new terminal.
If the installer itself fails with Could not find Codex package or platform npm release assets for Codex, that is a release-metadata problem rather than a PATH problem; see Could not find Codex package or platform npm release assets.
Sign in
There is no codex auth command. Run codex in a project directory; on first run choose Sign in with ChatGPT (OpenAI recommends this to use Codex as part of a Plus, Pro, Business, Edu, or Enterprise plan) or another available sign-in method.
codex # interactive; choose a sign-in method on first run
codex login # manage login
codex login status # show login status
codex logout # remove stored credentials
To use an API key instead (see OpenAI's authentication docs):
printenv OPENAI_API_KEY | codex login --with-api-key
Codex caches login details in ~/.codex/auth.json or in your operating system's credential store. The cli_auth_credentials_store setting in config.toml controls which (file, keyring, auto, or ephemeral) according to OpenAI's docs. If you use file storage, treat auth.json like a password.
Quick start
cd ~/projects/myapp
codex # interactive session
codex "explain what this codebase does" # start with a prompt
codex review # non-interactive code review
Configuration
Codex reads user-level configuration from ~/.codex/config.toml (on Windows, %USERPROFILE%\.codex\config.toml). Projects you trust can add .codex/config.toml overrides. A minimal file using keys from the same generator below:
model = "gpt-5.2-codex" # pick a model available to your account
model_reasoning_effort = "medium"
approval_policy = "on-request"
sandbox_mode = "workspace-write"
Command-line overrides use -c key=value, for example codex -c model="o3". The generator below produces the install command for your package manager and a matching config.toml. For more, see where Codex CLI stores its configuration files and OpenAI's config basics.
Codex CLI Config Generator
Generate config.toml and AGENTS.md for OpenAI’s Codex CLI — model, reasoning effort, approval policy, sandbox mode, and MCP servers. Optional private in-browser AI for the context file.
Open the full Codex CLI Config Generator tool →Updating and uninstalling
codex update # update to the latest version
Or re-run the method you installed with (see the table above). Full guide: how to update Codex CLI.
To uninstall an npm install: npm uninstall -g @openai/codex. Settings and sessions live in ~/.codex; delete that folder only if you want to remove them too. Run codex logout first to remove stored credentials.
Next steps
- Use Codex for Code Review - Built-in review command
- Resume Sessions - Continue previous conversations
- Use Image Input - Convert designs to code
- Configure Sandbox Modes - Control file access
- See where Codex CLI stores its configuration files
Compare other AI coding CLIs
- Install Claude Code CLI, Anthropic's agentic terminal assistant
- Install Google Gemini CLI for its 1M-token context window
- Install GitHub Copilot CLI if you already pay for GitHub Copilot
- Compare AI coding CLI pricing across tools and read Claude Code pricing explained