Fix Homebrew Codex Binary Conflict | Generated by AI

Home 2026.02

Question: Why does brew install --cask codex fail with the error “It seems there is already a Binary at ‘/opt/homebrew/bin/codex’” on macOS, and how to fix it?

Answer:

This error occurs because Homebrew detects an existing codex binary already present at /opt/homebrew/bin/codex (the standard location for Homebrew-linked binaries on Apple Silicon Macs). Homebrew’s cask installation process refuses to overwrite or replace an existing file there to avoid accidentally breaking your current setup.

The most common cause in your case (given your earlier codex --version showed codex-cli 0.36.0) is that you previously installed Codex via npm (npm install -g @openai/codex), which placed its binary in a global npm bin directory (often /opt/homebrew/bin on Apple Silicon when using Homebrew-installed Node, or ~/.npm-global/bin, with a symlink). Later, when you try the Homebrew cask method, it conflicts because both methods try to manage the same command name (codex) in the same path.

How to confirm the current installation source

Run:

which codex
  1. Keep using npm (simplest if you prefer npm ecosystem)
    • Uninstall the attempted cask first (if partially installed):
      brew uninstall --cask codex
      
    • Update your existing npm version to the latest (as of February 2026, versions are in the 0.9x range):
      npm install -g @openai/codex@latest
      codex --version   # should show something like 0.98.0 or higher
      
  2. Switch to Homebrew cask (recommended by many for macOS, avoids npm/Node dependency)
    • First, remove the conflicting binary (most likely from npm):
      npm uninstall -g @openai/codex
      
      • If the binary still exists, manually remove the link:
        rm /opt/homebrew/bin/codex
        

        (Be careful: only do this if you’re sure it’s from npm and not needed elsewhere.)

    • Now retry the cask install:
      brew install --cask codex
      
    • It should succeed and place a fresh binary at /opt/homebrew/bin/codex.
    • Verify:
      codex --version   # expect a recent Rust-based version like 0.98.0+
      
  3. Clean everything and reinstall via one method
    • Uninstall both:
      brew uninstall --cask codex   # ignore if not installed
      npm uninstall -g @openai/codex
      rm -f /opt/homebrew/bin/codex   # force-remove symlink/binary if still there
      
    • Then install via your preferred method (npm or brew –cask).

Notes:

References:


Back Donate