Skip to content

How to Install Codex: A Beginner's Guide

Install Codex to deploy a terminal-based coding agent capable of inspecting code, making changes, and executing local development tools securely.

Tuan Tran Van
5 min read
Contents (9 sections)
  1. Step 1 — Install Codex
  2. Step 2 — Verify the install
  3. Step 3 — Sign in to Codex
  4. Step 4 — Choose the permission mode for your session
  5. Step 5 — Run your first task in a project
  6. Commands you will use every day
  7. Troubleshooting common problems
  8. What to do next
  9. References

When you finish, you have a coding agent running in your terminal — it reads the files in your project, edits them, and runs commands on your machine.

These steps install Codex, sign you in, and get your first task running.

You need an OpenAI account — a ChatGPT plan or an API key — and a terminal. The standalone installer and the Homebrew cask drop in a native binary, so Node.js only matters if you install through npm, where the package requires Node.js 16 or later. For background on what the agent actually does, read What Is Codex?.

A Codex CLI session in a terminal: it takes a request to explain the codebase, then lays out a step-by-step plan

Step 1 — Install Codex

Pick one — skip the others.

Three install routes to Codex — standalone installer, npm, and Homebrew — converging on a single binary

Use the standalone installer

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

This downloads the Codex CLI binary and installs it directly to your system. It is the fastest path on macOS and Linux.

Use npm

bash
npm install -g @openai/codex

This installs the CLI package globally. On Arm Linux (Ubuntu/Debian), install Node.js from NodeSource first if it is missing.

Use Homebrew

bash
brew install --cask codex

This installs Codex as a cask on macOS.

Step 2 — Verify the install

bash
codex --version

The output resembles @openai/codex, 0.146.0. That confirms the binary is on your PATH and executable from any directory.

Step 3 — Sign in to Codex

Pick one — skip the others.

Browser-based login

bash
codex login

This opens a browser window and authenticates the session with your ChatGPT account.

API Key login

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

This authenticates the CLI with an OpenAI API key, which bills usage at API rates instead of drawing on ChatGPT plan credits.

Access Token login

bash
printenv CODEX_ACCESS_TOKEN | codex login --with-access-token

Use this for enterprise automation, non-interactive workflows, and headless environments.

Step 4 — Choose the permission mode for your session

Set the agent's boundaries with the --sandbox flag at launch, or with the /permissions command mid-session.

  • workspace-write: reads and edits inside the project directory. The .git, .agents, and .codex directories stay read-only even in this mode.
  • read-only: reads files and answers questions, and changes nothing.

Start a session with explicit permissions:

bash
codex --sandbox workspace-write --ask-for-approval on-request

A folder without a .git directory defaults to read-only, so Codex will not edit anything there until you change the mode.

The workspace-write and read-only permission modes compared, with read-only as the default for a folder without a .git directory

Step 5 — Run your first task in a project

bash
codex

Run this from inside a project repository. Give it an opening task, such as "Tell me about this project" or "Improve documentation in [filename]", to start the session in that working directory.

Commands you will use every day

CommandDescription
codex login statusCheck the current authentication state and active account.
codex reviewReview uncommitted changes or find issues in a commit.
/modelChoose the active model and reasoning effort.
codex logoutClear stored credentials from the local system.

Troubleshooting common problems

Error MessageLikely CauseFix
npm warn EBADENGINE Unsupported engineNode.js is below the package's >=16 floor.Run nvm install 20 && nvm alias default 20, then reinstall.
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@openai'The global npm directory is owned by root.Run sudo chown -R $(whoami) $(npm prefix -g)/lib/node_modules.
Network calls fail inside a taskSandbox network access is off by default.Run codex -c 'sandbox_workspace_write.network_access=true', or set it in config.toml.
WSL1 is no longer supportedThe Linux sandbox moved to bwrap in Codex 0.115.Upgrade to WSL2.

What to do next

Run /init inside your repository to generate an AGENTS.md scaffold. That file holds the instructions Codex reads on every later session in the project — conventions, test commands, and what to leave alone. See AGENTS.md best practices.

References

Read more

Share this article