Install Codex CLI With Homebrew

Homebrew is one way to install the Codex CLI on macOS. This guide walks through the installation steps, authentication choices after install, and what to check if the setup does not work as expected.

Updated 4 min read

Homebrew is a popular package manager for macOS and Linux that makes it straightforward to install, update, and remove command-line tools. If you already use Homebrew for other tools, installing the Codex CLI through it keeps everything under one management system. If you prefer Node.js tools, the npm path works on any platform.

Installation gets the tool onto your machine. What the tool does when it runs depends on the project context it reads at the start of each session. A tool like fenbs keeps that context, including the project rules and current tasks, outside the CLI so any session can read it without a manual briefing.

Before you install

You need an OpenAI account with API access. Codex CLI makes API calls and each session uses tokens from your account. If you do not have an API key yet, create one at platform.openai.com before the install, so you can authenticate immediately after.

If you are installing on macOS, Xcode Command Line Tools must be present. Homebrew requires them. Install them with xcode-select --install if you have not already.

Check whether Homebrew itself is installed: run brew --version in your terminal. If it is not, install it from brew.sh first, then return to this guide.

Install Codex CLI with Homebrew

The Codex CLI may be available through the main Homebrew formulae or through an OpenAI tap. Check the OpenAI Codex repository (opens in a new tab) for the current Homebrew install command, because the exact formula name can change between releases. A typical install looks like:

Install via Homebrew (check the repo for the current command)
brew install openai/tap/codex
# or if available in the main formulae:
brew install codex

If the install uses a tap, Homebrew will add the tap first and then install the formula. Follow any prompts during the install. When it finishes, confirm the install worked:

Confirm the install
codex --version

Install with npm if you prefer

If you manage Node.js tools with npm or prefer a cross-platform install path, npm works on macOS, Linux, and Windows:

Install via npm
npm install -g @openai/codex

Run codex --version after install to confirm. If the command is not found, your npm global bin directory may not be on your PATH. Check with npm bin -g and add that directory to your shell's PATH.

The Homebrew and npm versions should be functionally equivalent; the main difference is how you update them later. With Homebrew: brew upgrade codex. With npm: npm install -g @openai/codex.

Authenticate after install

The two main authentication methods are codex auth and setting the OPENAI_API_KEY environment variable.

codex auth opens a browser sign-in, which is the simplest path for a personal machine. Run it once; the credential is stored locally. Every future codex run reads it automatically.

Authenticate with a browser sign-in
codex auth

For a server, a CI pipeline, or a shared machine where a browser sign-in is not practical, set the API key in your shell profile:

Set an API key (add to ~/.zshrc or ~/.bashrc)
export OPENAI_API_KEY=your-key-here

See codex cli authentication for a full walkthrough of both methods, including how to handle account mismatches.

Check a fresh install

Run a simple task to confirm the end-to-end setup works:

Quick test
codex "List the files in the current directory and describe what each one does"

If it runs and returns a response, the install and authentication are working. If it returns an API error, check that your key is set correctly and that the account has sufficient quota.

For codex cli on windows, the npm path is the standard route since Homebrew targets macOS and Linux.

Common install issues

  • command not found: codex after install: the install directory is not on your PATH. For Homebrew, run brew doctor to check. For npm, run npm bin -g and add the result to your PATH.
  • Permission errors during install: do not use sudo with Homebrew. For npm globals, set a user-writable npm prefix rather than running as root.
  • Outdated Homebrew formulae: run brew update before installing to make sure you get the current version of the formula.
  • API key not recognized: confirm the key is exported in the same shell where you run codex. A key set in one terminal window is not visible in another unless it is in your shell profile.
How fenbs helps

Give the new assistant a project to start from

Once Codex CLI is installed and authenticated, connect it to fenbs over MCP from Integrations. Add your project with its current tasks and Decisions and rules. The next time you open a session, the assistant reads the project context before it does anything, so you brief it once and it works from that record every time after. Create a free account to get started.

Create a free account

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

Keep Codex CLI current

Codex CLI is updated regularly. New versions add model support, fix tool-calling behavior, and sometimes change flag names. Check the OpenAI Codex repository (opens in a new tab) for the latest release notes before starting a large project.

With Homebrew, update alongside your other tools by running brew update and brew upgrade on a regular schedule. With npm, reinstall the package globally to get the latest version. Running codex --version before a long session confirms you are on a recent release and avoids running into a fixed bug on an old version.

How to do this with fenbs

  1. Create a free account and add your first project. Write the goal, any standing rules, and the current tasks.
  2. Install and authenticate Codex CLI as described above.
  3. Connect Codex CLI to fenbs over MCP from Integrations. The sign-in is a browser flow separate from your OpenAI authentication.
  4. Open a Codex CLI session and ask it to read the project context from fenbs: rules first, then current tasks and Where we left off.
  5. Before the session ends, ask it to save progress. The next session on any machine picks up from the same point.

Questions people ask.

How do I install Codex CLI on macOS?

Two main options: Homebrew using the formula from the OpenAI tap, or npm global install. Check the Codex repository for the current Homebrew formula name. Both produce the same codex command; the difference is how you update it.

What do I do if "codex" is not found after installing with Homebrew?

The install directory may not be on your PATH. Run brew doctor to check for PATH issues. You can also run which codex to see if the binary is installed, and then add its directory to your PATH.

Do I need to use brew to keep Codex CLI up to date?

Only if you installed with Homebrew. Use brew upgrade to update it. If you installed with npm, reinstall the package globally to get the latest version. The update command matches the install method.

Does Codex CLI work on Linux with Homebrew?

Homebrew supports Linux as well as macOS, so the same install command works. On Linux, Homebrew installs to a different prefix by default; follow the post-install instructions that appear to add it to your PATH.

More in Agent harness (for developers)

All Agent harness (for developers) articles

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.