Skip to main content
OpenAIbeginner

Install Codex CLI: Fix "command not found" & PATH Errors

Fix "zsh: command not found: codex" and PATH errors after installing the OpenAI Codex CLI, then install and sign in on macOS, Linux, and Windows.

8 min readUpdated December 2026

By

Want us to handle this for you?

Get expert help →

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 -g changes when you switch versions. Run nvm use <version> for the version you installed under, or reinstall with npm install -g @openai/codex after switching.
  • Volta: install with volta install @openai/codex so 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):

MethodInstallUpdate
macOS/Linux installercurl -fsSL https://chatgpt.com/codex/install.sh | shre-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
npmnpm install -g @openai/codexnpm install -g @openai/codex
Homebrewbrew install --cask codexbrew upgrade --cask codex
Release binarydownload the archive for your platform from the latest GitHub Release and rename the extracted file to codexdownload 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 →
Loading interactive 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

Compare other AI coding CLIs

Running models locally?

Turn your GPU into an OpenAI-compatible endpoint

Wide Area Intelligence is an edge-first AI gateway — it serves the GPU you already own over a Cloudflare Tunnel as an OpenAI-compatible endpoint, edge-caches repeated requests, and bursts to the cloud only when your node is offline. Works with any OpenAI SDK.

Start routing — free

Frequently Asked Questions

Find answers to common questions

Run 'which codex' to see whether the shell can find it, then 'npm prefix -g' to find where npm installed it. On macOS and Linux the executable is in the bin folder under that prefix, so add it to PATH (for zsh: echo 'export PATH="$(npm prefix -g)/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc) and run 'rehash'. On Windows the executable is in the prefix folder itself. Note that 'npm bin -g' no longer works: npm removed it in npm 9.

OpenAI documents four ways: the standalone installer (curl -fsSL https://chatgpt.com/codex/install.sh | sh on macOS/Linux, or the install.ps1 PowerShell installer on Windows), npm install -g @openai/codex, brew install --cask codex, or a binary from the GitHub Releases page. Then run 'codex --version' to verify.

Run 'codex' and choose Sign in with ChatGPT (or another available sign-in method). You can also run 'codex login'; 'codex login status' shows whether you are signed in and 'codex logout' removes stored credentials. There is no 'codex auth' command. For an API key, use 'printenv OPENAI_API_KEY | codex login --with-api-key'.

Only the npm install needs Node. The @openai/codex package declares engines.node >= 16 in its npm metadata (checked with 'npm view @openai/codex engines'). The standalone installer and the Homebrew cask do not need Node.

OpenAI's README says to sign in with ChatGPT to use Codex as part of a Plus, Pro, Business, Edu, or Enterprise plan. You can also use an API key, which is billed by API usage. See OpenAI's Codex pricing pages for current limits.

Usually a Node version manager. nvm installs global packages under each Node version, so switching versions changes which global packages are on PATH. Run 'which codex' and 'npm prefix -g' in the failing terminal, or install with the standalone installer, which does not depend on npm's prefix.

Run 'codex update', or re-run the method you installed with (npm install -g @openai/codex, brew upgrade --cask codex, or the installer script). To remove an npm install, run 'npm uninstall -g @openai/codex'.

Codex CLI is a terminal-based coding agent that runs locally, can read your codebase, run commands, and modify files. ChatGPT is OpenAI's chat interface. Signing in to Codex with your ChatGPT account lets it use your ChatGPT plan.