Install Codex CLI on macOS, Linux and Windows
Install OpenAI's Codex CLI with the install script, npm or Homebrew on macOS, Linux and Windows, sign in, and fix codex: command not found.
On macOS or Linux, run curl -fsSL https://chatgpt.com/codex/install.sh | sh; on Windows, run OpenAI’s PowerShell installer, irm https://chatgpt.com/codex/install.ps1 | iex (the full line is below). Neither needs Node. With Node.js 16 or newer you can instead run npm install -g @openai/codex, and on Homebrew it is a cask: brew install --cask codex. Open a new terminal, check with codex --version (0.172.0 is the latest release, published November 24, 2026), then run codex in a project folder and choose Sign in with ChatGPT. On a machine with no browser, sign in with codex login --device-auth.
Pick an install method
Every route installs the same program, a native binary; they differ in what they need and how they update. As of 0.172.0, from the repository’s README:
| Method | Command | Needs | Lands in |
|---|---|---|---|
Install script (macOS, Linux) | curl -fsSL https://chatgpt.com/codex/install.sh | sh | curl | ~/.local/bin/codex |
Install script (Windows) | the PowerShell line under Windows, below | 64-bit Windows | %LOCALAPPDATA%\Programs\OpenAI\Codex\bin |
npm | npm install -g @openai/codex | Node.js 16+ | npm’s global bin |
Homebrew | brew install --cask codex | Homebrew | $(brew --prefix)/bin/codex |
Release archive | download, extract, rename | nothing | wherever you put it |
OpenAI’s CLI docs lead with the script, “the standalone installer for macOS and Linux”, and it is the one that keeps Codex entirely in your home folder, so neither installing nor updating ever needs sudo. Use npm if you already manage tools through it, and Homebrew if that is how your Mac is kept.
The install script on macOS and Linux
curl -fsSL https://chatgpt.com/codex/install.sh | shCopiedReading the script as served in November 2026: it supports x86_64 and arm64 on macOS and Linux, keeps the releases under ~/.codex, and links codex into ~/.local/bin (CODEX_INSTALL_DIR picks another folder). If that folder is not on your PATH, it adds an export PATH line, between # >>> Codex installer >>> markers, to one shell file:
| System and shell | File it edits |
|---|---|
macOS, zsh | ~/.zprofile |
macOS, bash | ~/.bash_profile |
Linux, bash | ~/.bashrc |
Linux, zsh | ~/.zshrc |
Anything else | ~/.profile |
It ends with “Codex CLI 0.172.0 installed successfully.” and two hints: a Current terminal: line with the export to paste into the window you are in, and “Future terminals: open a new terminal and run: codex”. The installers download from releases.openai.com and, per the README, “fall back to GitHub Releases if a metadata or asset download is unavailable.” To pin a version, pass it in CODEX_RELEASE; updating Codex has the forms for that and for going back one.
Piping a script into sh runs whatever the server sends. If you would rather read it first, download it, look, then run it:
curl -fsSL https://chatgpt.com/codex/install.sh -o codex-install.sh
less codex-install.sh
sh codex-install.shCopiednpm
npm install -g @openai/codexCopiedThe package declares Node >=16. It is a small launcher; the program itself comes as a per-platform optional dependency, with builds for Linux, macOS and Windows on x64 and arm64. If optional dependencies were skipped, the launcher stops with Missing optional dependency @openai/codex-linux-x64 (or your platform’s name) and prints the reinstall command to run.
Where it lands depends on how Node was installed. With Node from a system package, npm’s global folder belongs to root, so the install needs sudo and so does every update; without it, npm fails with EACCES: permission denied. With nvm or another version manager, the global folder is in your home and no sudo is needed, but codex is only on PATH in shells where that Node version is active. What npm install -g does covers the global folder in full.
Homebrew
brew install --cask codexCopiedCodex is published as a cask, not a formula: Homebrew’s formula index has no codex, so use the --cask form the README gives. The cask was at 0.172.0 on November 25, links codex into Homebrew’s bin, and lists Linux builds for x86_64 and arm64 beside the macOS ones. Update it with brew upgrade --cask codex.
A release archive, by hand
Each GitHub release carries single-binary archives. The README names four: codex-aarch64-apple-darwin.tar.gz (Apple Silicon), codex-x86_64-apple-darwin.tar.gz (Intel Mac), codex-x86_64-unknown-linux-musl.tar.gz and codex-aarch64-unknown-linux-musl.tar.gz. The file inside keeps the platform in its name, so rename it:
tar -xzf codex-x86_64-unknown-linux-musl.tar.gz
mkdir -p ~/.local/bin
mv codex-x86_64-unknown-linux-musl ~/.local/bin/codex
codex --versionCopiedNothing updates a binary placed this way, and codex update cannot tell how it was installed; you download the next archive yourself.
Windows
Codex runs natively on Windows 11, and on a recent Windows 10 on a best-effort basis. The README’s Windows install, run in PowerShell:
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"CopiedThen open a new PowerShell window, since the installer adds its folder to your user PATH for windows opened afterwards. npm install -g @openai/codex works on Windows too. If your code lives in Linux, install Codex inside WSL2 with the Linux script instead; WSL1 is not supported. The sandbox setup prompt on first run, MXC, the execution-policy error and where the files go are in Codex on Windows.
First run and sign-in
cd ~/your-project
codexCopiedOn the first run, OpenAI’s docs say to “choose Sign in with ChatGPT or another available sign-in method.” The authentication page sets out the two kinds: ChatGPT sign-in “for subscription access”, using your plan’s Codex allowance (which plans include it is in a guide of its own), and an API key “for usage-based access”, billed at API rates.
- ChatGPT, with a browser on the same machine. A browser opens, you sign in, and the browser hands the sign-in back to Codex through a local callback on
localhost:1455. - ChatGPT, with no browser (a server, a container, an SSH session). Run
codex login --device-auth: it prints a link and a one-time code to approve from any browser. It works only once device code sign-in is switched on in your ChatGPT security settings; the device code guide covers the setting and the message you get while it is off. - API key.
printenv OPENAI_API_KEY | codex login --with-api-keyreads the key from standard input and saves it. AnOPENAI_API_KEYin the environment does not sign Codex in by itself; using Codex with an API key has the details.
The sign-in is saved in ~/.codex/auth.json, a plaintext file with live tokens, unless you set Codex to use the system’s credential store. codex login status shows which method is active, and codex logout clears it.
Linux: the sandbox wants bubblewrap
Codex runs the commands it chooses inside a sandbox, which on Linux is bubblewrap. It prefers the first bwrap on your PATH and falls back to a copy it bundles, with a startup warning, so install your distribution’s bubblewrap package. On Ubuntu 24.04 it also needs an AppArmor profile before it can create user namespaces, or every sandboxed command fails; the bubblewrap errors guide has each warning and its fix, and Codex on a Linux server walks a whole headless install.
Check it, and fix “codex: command not found”
codex --version # the installed version, 0.172.0 if it is the latest
command -v codex # which file runs (Get-Command codex in PowerShell)
type -a codex # every codex on the PATH, if there is more than oneCopiedIf the shell cannot find codex, the cause is nearly always the PATH:
- Right after the install script. The shell you installed from read its startup file before the installer changed it. Open a new terminal, or run the export line the installer printed, shown below.
- After npm. npm’s global
binfolder is not on PATH.npm prefix -gprints the prefix the command was installed under. With nvm, switch to the Node version you installed it under. - On Windows. The window was open before the install; open a new PowerShell window.
- Over
ssh host 'codex …', from cron or a service. Those never read the file the installer edited. Call Codex by its full path; the Linux server guide explains why and has a cron example.
# the current terminal, after the install script
export PATH="$HOME/.local/bin:$PATH"CopiedIf codex --version prints an old number, a second copy is earlier on the PATH, typically an npm install beside a script install. type -a codex lists them; keep one and remove the others with their own uninstall. From then on, codex update runs the right update for the install script, npm or Homebrew on a Mac, and the update guide covers it when it fails.