Agentic AI AcademyAgentic AI Academy

Installing the Codex CLI

npm, Homebrew cask, install scripts, and binaries on every OS

Beginner 12 minBuilder
What you'll be able to do
  • Install the Codex CLI four ways — npm, Homebrew cask, the official install scripts, and a prebuilt binary — and know when to reach for each
  • Avoid the two classic install traps: the unscoped 'codex' npm package and using a Homebrew formula instead of the cask
  • Read the supported-OS matrix and pick the right path on macOS (Apple Silicon + Intel), Linux (x86_64 + arm64), and Windows
  • Explain the Windows story: a native PowerShell sandbox vs WSL2, and why WSL1 was dropped at CLI 0.115
  • Run an unattended install in CI with CODEX_NON_INTERACTIVE, and redirect the install target with CODEX_INSTALL_DIR
  • Verify a fresh install and keep it current with codex update, checking the live releases page for the latest version
At a glance

The Codex CLI is an open-source agent written in Rust that runs locally on macOS, Linux, and Windows. This lesson is a complete, copy-paste install guide: the scoped npm package, the Homebrew cask (not a formula), the official install scripts including unattended mode, prebuilt binaries, the supported-OS matrix, the Windows native-sandbox-vs-WSL2 story, and how to verify and update what you installed.

  1. 1One binary, four front doors
  2. 2npm and Homebrew — and their two traps
  3. 3Install scripts (incl. unattended) and prebuilt binaries
  4. 4The supported-OS matrix
  5. 5Windows: native sandbox vs WSL2 (and why WSL1 is gone)
  6. 6Verify, then keep it current

One binary, four front doors

Start with the mental model, because it makes every command below obvious: the Codex CLI is a single self-contained codex binary, written in Rust. It is not a thick Node application; npm is just one of several delivery trucks that drop the same compiled binary onto your machine. Whether you install via npm, Homebrew, a shell script, or by downloading a tarball, you end up with the identical codex executable on your PATH.

That matters for two reasons. First, you don't need a particular package manager — pick whichever fits your environment. Second, because it's a native binary, it runs locally: it reads, edits, and runs code on your machine inside an OS-enforced sandbox, not in a remote container (that's the cloud surface, a separate lesson).

Here are the four front doors, all installing the same binary:

PathCommandBest for
npmnpm install -g @openai/codexAnyone with Node already; cross-platform
Homebrewbrew install --cask codexmacOS users on Homebrew
Install scriptcurl … install.sh | sh (or PowerShell)No Node/Homebrew; servers, CI
Prebuilt binaryDownload a tarball from GitHub ReleasesAir-gapped, pinned versions, custom PATH

The rest of this lesson walks each door, then covers the OS matrix, verifying, and updating.

Key insight

The package manager is just a delivery truck

Every install path yields the same Rust codex binary. You're not choosing a different product — only a different way to get the same executable onto your PATH. Pick the one that matches your machine.

npm and Homebrew — and their two traps

These are the two most common paths, and each has exactly one gotcha that bites newcomers.

npm (cross-platform)

bash
npm install -g @openai/codex

The trap: the package is the scoped @openai/codex. There is an unrelated, unofficial package published as the bare name codex on npm — installing that gives you the wrong tool entirely. Always include the @openai/ scope. The CLI requires Node ≥ 16, and it installs a codex command on your PATH.

Homebrew (macOS)

bash
brew install --cask codex

The trap: Codex ships as a Homebrew cask, not a formula. The --cask flag is mandatory — brew install codex (no flag) resolves to a different, unrelated formula. Casks deliver the prebuilt binary directly, which is exactly what you want here.

Both managers make updating trivial later (npm update -g @openai/codex, brew upgrade --cask codex), though Codex also ships its own codex update command (covered at the end).

Watch out

Two names that aren't Codex

npm install -g codex (no scope) and brew install codex (no --cask) both install unrelated tools, not OpenAI Codex. Use @openai/codex on npm and --cask codex on Homebrew, every time.

Install scripts (incl. unattended) and prebuilt binaries

When you don't have Node or Homebrew — a fresh server, a CI runner, a colleague's laptop — the official install scripts are the fastest route.

macOS / Linux

bash
curl -fsSL https://chatgpt.com/codex/install.sh | sh

Windows (PowerShell)

powershell
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"

Unattended / CI

The interactive script may prompt. For pipelines and scripted provisioning, set CODEX_NON_INTERACTIVE=1 so it never asks:

bash
curl -fsSL https://chatgpt.com/codex/install.sh | CODEX_NON_INTERACTIVE=1 sh

By default the script installs into ~/.local/bin (on Windows, %LOCALAPPDATA%\Programs\OpenAI\Codex\bin). Override the destination with CODEX_INSTALL_DIR — handy when ~/.local/bin isn't on PATH, or when you want one shared location on a build agent.

Prebuilt binaries (GitHub Releases)

For air-gapped machines, pinned versions, or full control over PATH, grab the platform tarball straight from GitHub Releases and drop codex somewhere on your PATH. The target triples you'll see:

PlatformAsset
macOS Apple Siliconcodex-aarch64-apple-darwin.tar.gz
macOS Intelcodex-x86_64-apple-darwin.tar.gz
Linux x86_64codex-x86_64-unknown-linux-musl.tar.gz
Linux arm64codex-aarch64-unknown-linux-musl.tar.gz

The Linux binaries are static musl builds, so they run on a wide range of distros without glibc-version headaches.

Tip

Two knobs for CI

CODEX_NON_INTERACTIVE=1 suppresses prompts and CODEX_INSTALL_DIR=/usr/local/bin (or any PATH dir) controls where the binary lands. Together they make the install script fully scriptable on a build agent.

Watch out

Read before you pipe to a shell

curl … | sh runs whatever the URL returns. It's fine from the official chatgpt.com/codex domain, but on locked-down or audited systems prefer the prebuilt-binary path so you can inspect and pin exactly what you run.

The supported-OS matrix

Codex runs natively on all three major desktop OSes. The detail that matters is which architectures and how the sandbox is enforced — because Codex refuses to run unsandboxed rather than act without an OS-enforced boundary, so the platform's sandbox support is part of "is this supported."

OSArchitecturesSandbox enforcement
macOSApple Silicon (arm64) + Intel (x86_64)Seatbelt (sandbox-exec), built in — rarely needs setup
Linuxx86_64 + arm64 (musl static)bubblewrap (bwrap) + seccomp, with Landlock as fallback
Windowsx86_64Native PowerShell sandbox or WSL2 (runs the Linux sandbox)

On macOS the sandbox is built into the OS, so installs "just work." On Linux, the most common first-run failure — "couldn't set up sandbox" — almost always means bubblewrap is missing or user namespaces are restricted; install/enable bubblewrap and it clears up. The Windows story has enough nuance that it gets its own section next.

Note

Why Codex cares about your sandbox

Codex won't run with the sandbox disabled when the platform can't enforce the policy — it would rather refuse than let the agent act without a boundary. So "supported OS" really means "OS where Codex can enforce read/write/network limits."

Windows: native sandbox vs WSL2 (and why WSL1 is gone)

Windows has two equally legitimate ways to run Codex, plus one version of WSL that no longer works. Get this right up front and you'll skip the most common Windows install headaches.

1. Native Windows (PowerShell sandbox). Codex runs directly on Windows using a PowerShell-based sandbox, configured in config.toml with two modes:

  • elevated (preferred) — dedicated lower-privilege sandbox users, filesystem permission boundaries, and firewall rules. Best isolation and performance.
  • unelevated (fallback) — a restricted token derived from your own user with ACL-based filesystem boundaries; weaker network isolation.

2. WSL2. Runs the full Linux sandbox (bubblewrap) inside Windows. Reach for it when you want a Linux-native environment — many toolchains assume Linux, and WSL2 gives you that without leaving Windows.

3. WSL1 — no longer supported. This is the gotcha. At CLI 0.115, the Linux sandbox moved to bubblewrap, which WSL1 cannot provide. WSL1 was supported only through 0.114 and dropped at 0.115. If you're on WSL1, upgrade your distro to WSL2 (wsl --set-version <distro> 2) before installing Codex.

Version guidance: Windows 11 is recommended; recent Windows 10 (1809+) is best-effort and depends on a modern console / ConPTY.

Watch out

On WSL1? Move to WSL2 first

Codex 0.115 switched the Linux sandbox to bubblewrap, which WSL1 can't run. WSL1 was the cutoff at 0.114. Convert with wsl --set-version <distro> 2, or run Codex natively on Windows instead.

Tip

Which Windows path?

Want it to feel like Windows and don't need a Linux toolchain? Use the native PowerShell sandbox. Your project assumes Linux (build scripts, shell tooling)? Use WSL2. Both are first-class — choose by your toolchain, not by Codex.

Verify, then keep it current

However you installed, confirm the binary is on PATH and runnable before you go further:

bash
codex --version      # prints the installed version
codex --help         # lists subcommands and global flags

If codex isn't found, the install directory likely isn't on your PATH — the script default is ~/.local/bin; add it to PATH (or reinstall with CODEX_INSTALL_DIR pointed at a directory that already is).

For a deeper sanity check, Codex ships a built-in diagnostic:

bash
codex doctor         # checks install, config, auth, runtime, Git, terminal

codex doctor generates a local report covering your install, config, auth state, and runtime; it's the first thing to run when something looks off (and --json produces a redacted report you can attach to a bug).

Updating

Codex updates itself with one command, regardless of how you installed it:

bash
codex update

If you installed via a package manager you can also use that manager (npm update -g @openai/codex, brew upgrade --cask codex). The CLI moves fast — new versions land frequently — so don't memorize a version number. Check the live releases page for what's current and what changed.

Watch out

Version numbers rot — check the live page

The latest CLI version changes constantly (the dossier's snapshot was already a moving target). Never hard-code or assume a version. Treat github.com/openai/codex/releases as the source of truth for the current release and its notes.

Tip

`codex doctor` is your first stop

Most "it won't start" reports — missing PATH entry, sandbox not available, auth not set — surface immediately in codex doctor. Run it before reaching for forums.

Try it: Install, verify, and update the Codex CLI

Goal: get a working codex binary on your machine and prove it. 1) Pick a path. On macOS choose brew install --cask codex (note the --cask) or npm install -g @openai/codex (note the scope); on Linux or a server use curl -fsSL https://chatgpt.com/codex/install.sh | sh; on Windows use either the PowerShell script (irm https://chatgpt.com/codex/install.ps1 | iex) or WSL2. 2) Verify. Run codex --version and codex --help — if codex isn't found, check that the install dir (default ~/.local/bin) is on your PATH. 3) Run the doctor. Execute codex doctor and read the report: note what it says about install, sandbox/runtime, and auth (you don't have to sign in yet). 4) Try the CI knobs (optional). In a throwaway dir, re-run the install script with CODEX_NON_INTERACTIVE=1 and a custom CODEX_INSTALL_DIR=$PWD/codex-bin, then confirm the binary appears there. 5) Check currency. Run codex update, then open github.com/openai/codex/releases and confirm your installed codex --version matches (or note how far behind you are). 6) Write three lines: which install path you used and why, one thing codex doctor flagged (or confirmed green), and the current release version from the live page. This cements the habit of verifying installs and trusting the live releases page over any memorized version number.

Key takeaways

  1. 1Codex is one Rust binary; npm, Homebrew, the install scripts, and prebuilt tarballs are just different ways to deliver the same `codex` executable to your PATH.
  2. 2Watch the two name traps: install the scoped `@openai/codex` on npm (not bare `codex`, which is unrelated) and use `brew install --cask codex` (it's a cask, not a formula).
  3. 3The install scripts (`curl … install.sh | sh`, or PowerShell `irm … install.ps1 | iex`) need no Node or Homebrew; set `CODEX_NON_INTERACTIVE=1` for CI and `CODEX_INSTALL_DIR` to relocate the binary (default `~/.local/bin`).
  4. 4Supported: macOS (Apple Silicon + Intel), Linux (x86_64 + arm64, static musl), and Windows — natively via a PowerShell sandbox or via WSL2.
  5. 5WSL1 was dropped at CLI 0.115 when the Linux sandbox moved to bubblewrap (supported only through 0.114); convert to WSL2 or run natively on Windows.
  6. 6Verify with `codex --version` / `codex doctor`, update with `codex update`, and check github.com/openai/codex/releases for the current version rather than memorizing one.

Quiz

Lock in what you learned

Check your understanding

0 / 4 answered

1.A teammate runs `npm install -g codex` and `brew install codex`, then complains Codex 'behaves nothing like the docs.' What went wrong?

2.You're provisioning a CI runner that has no Node and no Homebrew, and the build must never block on a prompt. Which approach fits best?

3.A developer on WSL1 installs the latest Codex CLI and it refuses to start its sandbox. What's the most likely cause and fix?

4.After installing, you want to confirm the install is healthy and keep it current. Which pairing is correct?

Go deeper

Hand-picked sources to keep learning