How to Install Codex CLI on Ubuntu 26.04, 24.04 and 22.04

Install Codex CLI on Ubuntu 26.04, 24.04, and 22.04 using npm, Homebrew, or binary. Covers authentication, commands, and troubleshooting.

Last updatedAuthorJoshua JamesRead time7 minGuide typeUbuntu

Installing Codex CLI on Ubuntu gives you OpenAI’s terminal coding agent inside the same shell where you already run git, package managers, tests, and project scripts. Codex can inspect a local repository, explain unfamiliar code, draft patches, review changes, and run commands with the approval and sandbox settings you choose.

OpenAI publishes Codex CLI through npm, Homebrew, and GitHub release binaries. The right method depends on whether your Ubuntu system already has a current Node.js setup, whether you use Homebrew on Linux, or whether you want a standalone binary that does not require npm at all.

Install Codex CLI on Ubuntu

Start by refreshing APT and installing the small HTTPS download prerequisites used later in the guide. The curl command handles the release downloads in the binary method:

sudo apt update
sudo apt install curl ca-certificates

If your account cannot run sudo, configure administrative access first with the Ubuntu sudoers setup guide, then return to the installation steps.

Ubuntu does not currently provide an APT package named codex for OpenAI Codex CLI, so sudo apt install codex is not the correct install path. Use one of the upstream methods below instead.

MethodSourceBest Fit
GitHub binaryOpenAI GitHub releasesUniversal Ubuntu path, no Node.js or npm required
npmnpm package @openai/codexSystems where you already maintain a current Node.js and npm setup
HomebrewHomebrew caskLinux Homebrew users who want cask-managed updates

For Ubuntu 26.04, 24.04, and 22.04, the binary method is the most consistent starting point because it avoids differences in Ubuntu’s default Node.js packages. Use npm when Node.js is already part of your workflow, and use Homebrew only if you already manage developer tools with Linuxbrew.

Ubuntu Node.js Package Notes

The current npm package declares a Node.js engine of >=16. Ubuntu’s default Node.js packages differ by release, which affects whether the npm method is a clean choice on a fresh system:

Ubuntu ReleaseDefault nodejs CandidateCodex npm Method
Ubuntu 26.0422.xMeets the current Codex npm engine
Ubuntu 24.0418.xMeets the current engine, but use your normal current Node.js source if you need newer JavaScript tooling
Ubuntu 22.0412.xToo old for the current Codex npm package; use the binary method or install a newer Node.js line first

If you need a newer Node.js stack before using npm, the Ubuntu Node.js installation guide covers repository, NodeSource, and NVM options. Return here after node --version reports Node.js 16 or newer.

Method 1: Install Codex CLI with GitHub Binary

The GitHub release binary is the simplest no-npm method. It works well on clean Ubuntu desktops, servers, and SSH systems because it only downloads the prebuilt Codex executable for your CPU architecture. The manual commands below show the transparent install path, and the optional helper script gives you a reusable update command for the same binary workflow.

Check your architecture first:

uname -m
x86_64

Most Intel and AMD Ubuntu systems show x86_64. ARM64 systems usually show aarch64.

Install on x86_64 Systems

Download the latest x86_64 release, extract the tar.gz archive, and copy the binary into /usr/local/bin:

curl -fL -o codex.tar.gz https://github.com/openai/codex/releases/latest/download/codex-x86_64-unknown-linux-musl.tar.gz
tar -xzf codex.tar.gz
sudo install -m 0755 codex-x86_64-unknown-linux-musl /usr/local/bin/codex
rm codex.tar.gz codex-x86_64-unknown-linux-musl

Install on ARM64 Systems

If uname -m returns aarch64, use the ARM64 archive instead:

curl -fL -o codex.tar.gz https://github.com/openai/codex/releases/latest/download/codex-aarch64-unknown-linux-musl.tar.gz
tar -xzf codex.tar.gz
sudo install -m 0755 codex-aarch64-unknown-linux-musl /usr/local/bin/codex
rm codex.tar.gz codex-aarch64-unknown-linux-musl

The install -m 0755 command copies the binary and marks it executable in one step, which avoids a separate chmod command.

Optional: Create a Reusable Binary Installer

If you expect to update Codex CLI regularly, create a small installer command instead of repeating the architecture-specific download sequence each time. The script detects your CPU architecture, downloads the matching OpenAI release asset into your user cache, installs the binary to /usr/local/bin/codex, verifies the result, and removes its temporary files.

Create the reusable command under /usr/local/bin:

sudo tee /usr/local/bin/update-codex-cli >/dev/null <<'EOF'
#!/usr/bin/env bash
set -euo pipefail

if [ "$(id -u)" -eq 0 ]; then
    echo "Run this script as your normal user; it will use sudo for the install step." >&2
    exit 1
fi

if ! command -v curl >/dev/null 2>&1; then
    echo "curl is required. Install it with: sudo apt install curl ca-certificates" >&2
    exit 1
fi

if ! command -v tar >/dev/null 2>&1; then
    echo "tar is required. Install it with: sudo apt install tar" >&2
    exit 1
fi

if ! command -v sudo >/dev/null 2>&1; then
    echo "sudo is required for installation under /usr/local/bin." >&2
    exit 1
fi

arch="$(uname -m)"
case "$arch" in
    x86_64)
        artifact="codex-x86_64-unknown-linux-musl"
        ;;
    aarch64|arm64)
        artifact="codex-aarch64-unknown-linux-musl"
        ;;
    *)
        echo "Unsupported CPU architecture: $arch" >&2
        exit 1
        ;;
esac

cache_root="${XDG_CACHE_HOME:-$HOME/.cache}/codex-cli"
mkdir -p "$cache_root"
work_dir="$(mktemp -d "$cache_root/download.XXXXXX")"
trap 'rm -rf "$work_dir"' EXIT

archive="$work_dir/codex.tar.gz"
download_url="https://github.com/openai/codex/releases/latest/download/${artifact}.tar.gz"
target="/usr/local/bin/codex"
backup_path=""

restore_backup() {
    if [ -n "$backup_path" ] && [ -e "$backup_path" ]; then
        sudo install -m 0755 "$backup_path" "$target"
    fi
}

echo "Checking sudo access..."
sudo true

echo "Downloading Codex CLI for $arch..."
curl -fsSL -o "$archive" "$download_url"

echo "Extracting archive..."
tar -xzf "$archive" -C "$work_dir"

if [ -e "$target" ]; then
    backup_path="$work_dir/codex.backup"
    sudo cp -a "$target" "$backup_path"
fi

echo "Installing Codex CLI to /usr/local/bin/codex..."
if ! sudo install -m 0755 "$work_dir/$artifact" "$target"; then
    echo "Install failed; restoring the previous Codex binary if one existed." >&2
    restore_backup
    exit 1
fi

echo "Installed version:"
if ! "$target" --version; then
    echo "Version check failed; restoring the previous Codex binary if one existed." >&2
    restore_backup
    exit 1
fi
EOF

sudo chmod +x /usr/local/bin/update-codex-cli

Run the helper whenever you want to install or update the binary release:

update-codex-cli
Checking sudo access...
Downloading Codex CLI for x86_64...
Extracting archive...
Installing Codex CLI to /usr/local/bin/codex...
Installed version:
codex-cli 0.x.x

The helper still uses the same official release files as the manual binary method. Its main advantage is repeatability: one command now handles architecture selection, download cleanup, installation, and version verification.

Verify the Binary Install

Confirm that your shell can run Codex CLI:

codex --version
codex-cli 0.x.x

Method 2: Install Codex CLI with npm

The npm method is OpenAI’s package-manager path for users who already maintain Node.js and npm. Check your current versions before installing Codex CLI this way:

node --version
npm --version
v22.x.x
10.x.x

If node --version reports a version older than 16, skip this method until you install a newer Node.js line, or use the GitHub binary method.

Install Codex into a user-owned prefix so npm does not need root permissions for the global package:

mkdir -p ~/.local/bin
grep -qxF 'export PATH="$HOME/.local/bin:$PATH"' ~/.bashrc || printf '%s\n' 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
export PATH="$HOME/.local/bin:$PATH"
npm install -g @openai/codex --prefix "$HOME/.local"

Avoid sudo npm install -g @openai/codex. Using a home-directory prefix keeps the package, generated command, and future updates owned by your account instead of root.

Verify the npm-managed command:

codex --version
codex-cli 0.x.x

Method 3: Install Codex CLI with Homebrew

Use the Homebrew method only if Linuxbrew is already part of your Ubuntu toolchain. If Homebrew is not installed yet, follow the Ubuntu Homebrew installation guide first, then return here.

Install the official Homebrew cask:

brew install --cask codex

Homebrew installs the Codex release binary and manages related cask updates through the same brew workflow you use for other developer tools.

Verify the Homebrew install:

codex --version
codex-cli 0.x.x

Authenticate Codex CLI

Codex CLI needs OpenAI authentication before it can send prompts and code context to the model. OpenAI’s current README lists ChatGPT Plus, Pro, Business, Edu, and Enterprise plans for ChatGPT sign-in, with API-key authentication available as a separate setup path through the official Codex authentication documentation.

Sign In with ChatGPT

Start Codex inside a project directory:

cd ~/your-project
codex

Choose the ChatGPT sign-in option when prompted. Codex opens a browser-based login flow, then stores local configuration, credentials, and session data under ~/.codex/.

Check or reset your login state with these commands:

codex login status
codex logout
codex login

Sign In with an API Key

For SSH sessions or systems without a browser, pipe an API key into the login command. This avoids saving the key directly in your shell history:

read -rsp "OpenAI API key: " OPENAI_API_KEY
printf '\n'
printf '%s' "$OPENAI_API_KEY" | codex login --with-api-key
unset OPENAI_API_KEY

You can also use an existing environment variable:

printenv OPENAI_API_KEY | codex login --with-api-key

Use Codex CLI on Ubuntu

These Ubuntu commands install the terminal CLI. OpenAI also references Codex Web, IDE integrations, and a desktop app flow, but those are separate from the Ubuntu shell command installed here. Run codex --help whenever you need the complete current command list.

Interactive and Non-Interactive Prompts

Launch an interactive Codex session from a project directory:

codex

You can also start with an initial prompt:

codex "explain the authentication flow in this project"

Use exec for a non-interactive task:

codex exec "summarize this repository and list risky files"

Review Local Changes

Codex can review uncommitted work, a branch comparison, or a specific commit:

codex review --uncommitted
codex review --base main
codex review --commit HEAD~1

Add a prompt when you want to narrow the review focus:

codex review --uncommitted "focus on authentication and file-permission risks"

Resume Sessions and Apply Diffs

Resume a previous session, fork the latest session, or apply the latest Codex-generated diff to your working tree:

codex resume
codex resume --last
codex fork --last
codex apply

Use Images and Model Options

Attach screenshots or diagrams when visual context matters:

codex -i screenshot.png "describe the UI changes needed"

Use a model flag only when you intentionally need a specific model available to your account:

codex -m <model> "refactor this function"

Choose a Sandbox Mode

Sandbox modes control what Codex can do while it works:

  • read-only: lets Codex inspect files without writing changes.
  • workspace-write: allows edits in the project workspace while keeping broader filesystem access limited.
  • danger-full-access: removes filesystem restrictions and should be reserved for trusted, intentional work.
codex --sandbox read-only
codex --sandbox workspace-write
codex --sandbox danger-full-access

The --full-auto flag is a convenience mode for low-friction sandboxed automatic execution. It is different from the dangerous bypass flag, which disables both approvals and sandboxing.

codex --full-auto

Do not use --dangerously-bypass-approvals-and-sandbox unless you fully trust the repository, prompt, and command side effects. The flag name is intentionally explicit because it removes core safety controls.

Update Codex CLI

Update Codex CLI with the same method you used to install it.

Update npm Install

export PATH="$HOME/.local/bin:$PATH"
npm install -g @openai/codex@latest --prefix "$HOME/.local"
codex --version

Update Homebrew Install

brew upgrade --cask codex
codex --version

Update Binary Install

Binary installs update by replacing the existing file with the latest release for your architecture. If you created the reusable helper, run it again:

update-codex-cli

If you used the manual binary steps instead, repeat the matching architecture block below.

For x86_64 systems:

curl -fL -o codex.tar.gz https://github.com/openai/codex/releases/latest/download/codex-x86_64-unknown-linux-musl.tar.gz
tar -xzf codex.tar.gz
sudo install -m 0755 codex-x86_64-unknown-linux-musl /usr/local/bin/codex
rm codex.tar.gz codex-x86_64-unknown-linux-musl
codex --version

For ARM64 systems:

curl -fL -o codex.tar.gz https://github.com/openai/codex/releases/latest/download/codex-aarch64-unknown-linux-musl.tar.gz
tar -xzf codex.tar.gz
sudo install -m 0755 codex-aarch64-unknown-linux-musl /usr/local/bin/codex
rm codex.tar.gz codex-aarch64-unknown-linux-musl
codex --version

Troubleshoot Codex CLI

APT Cannot Locate Codex

If APT reports that it cannot locate a codex package, that is expected. OpenAI Codex CLI is not installed from Ubuntu’s APT repositories, so use the binary, npm, or Homebrew method instead.

Codex Command Not Found

For npm installs using the user-owned prefix, make sure ~/.local/bin is in your current PATH:

export PATH="$HOME/.local/bin:$PATH"
command -v codex
/home/username/.local/bin/codex

For binary installs, confirm that the file exists in /usr/local/bin:

ls -l /usr/local/bin/codex

Node.js Is Too Old for npm

Ubuntu 22.04’s default Node.js 12 package is too old for the current Codex npm package. Check your version before troubleshooting npm errors:

node --version
v12.22.x

If you see an older major version, use the binary method or install a newer Node.js line before retrying npm.

npm Permission Errors

If npm fails with an EACCES permission error, reinstall Codex with the user-owned prefix shown earlier:

npm install -g @openai/codex --prefix "$HOME/.local"

Then refresh your current shell PATH:

export PATH="$HOME/.local/bin:$PATH"
codex --version

Authentication Fails or Uses the Wrong Account

Check the active login, sign out, then start a fresh login flow:

codex login status
codex logout
codex login

If you want a full local reset, remove the Codex configuration directory after signing out. This deletes saved credentials and session history:

rm -rf ~/.codex
codex login

Binary Architecture Mismatch

If the downloaded binary does not run, recheck the architecture and reinstall with the matching archive:

uname -m
aarch64

Use codex-aarch64-unknown-linux-musl.tar.gz for aarch64 systems and codex-x86_64-unknown-linux-musl.tar.gz for x86_64 systems.

Remove Codex CLI

Remove Codex CLI with the same method you used to install it.

Remove npm Install

npm uninstall -g @openai/codex --prefix "$HOME/.local"
rm -f ~/.local/bin/codex

Remove Homebrew Install

brew uninstall --cask codex

Remove Binary Install

sudo rm -f /usr/local/bin/codex /usr/local/bin/update-codex-cli

Remove Local Codex Data

Codex stores local configuration, authentication state, and session history in ~/.codex/. Remove this directory only when you want a full reset or permanent uninstall.

This command permanently deletes Codex CLI configuration, credentials, and local session history for your user account.

rm -rf ~/.codex

Verify that the command has been removed from your PATH:

command -v codex || echo "codex removed"
codex removed

Conclusion

Codex CLI is ready on Ubuntu after codex --version works and codex login status shows the account you intend to use. The GitHub binary is the most consistent no-npm path across Ubuntu 26.04, 24.04, and 22.04, while npm and Homebrew remain useful when those package managers already fit your workstation setup.

If you compare terminal coding assistants, related Ubuntu guides cover Gemini CLI, Claude Code, and GitHub Copilot CLI.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

We read and reply to every comment - let us know how we can help or improve this guide.

Verify before posting: