# 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.

Source: https://camnangai.com/en/tools/how-to-install-codex  
Published: 2026-07-31

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 a terminal and an OpenAI account, either a ChatGPT plan or an API key. 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?](https://camnangai.com/en/tools/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](https://camnangai.com/articles/huong-dan-cai-dat-codex/01-infographic.webp)

## Step 1 — Install Codex

Pick one — skip the others.

![Three install routes to Codex — standalone installer, npm, and Homebrew — converging on a single binary](https://camnangai.com/articles/huong-dan-cai-dat-codex/02-en.webp)

### 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, and it keeps Node.js versions out of the picture entirely.

### 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 whichever one matches the account you already have.

### 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](https://camnangai.com/articles/huong-dan-cai-dat-codex/03-en.webp)

## 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. On a repository I care about I start in `read-only` and switch to `workspace-write` only after I have seen what it wants to do, because an unexpected diff is much cheaper to read than to undo.

## Commands you will use every day

| Command              | Description                                                |
| :------------------- | :--------------------------------------------------------- |
| `codex login status` | Check the current authentication state and active account. |
| `codex review`       | Review uncommitted changes or find issues in a commit.     |
| `/model`             | Choose the active model and reasoning effort.              |
| `codex logout`       | Clear stored credentials from the local system.            |

## Troubleshooting common problems

| Error Message                                                                            | Likely Cause                                       | Fix                                                                                       |
| :--------------------------------------------------------------------------------------- | :------------------------------------------------- | :---------------------------------------------------------------------------------------- |
| `npm warn EBADENGINE Unsupported engine`                                                 | Node.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 task                                                         | Sandbox 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 supported`                                                            | The 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](https://camnangai.com/en/for/developers/agents-md-best-practices).

## References

- [Codex CLI | ChatGPT Learn](https://learn.chatgpt.com/docs/codex/cli)
- [Authentication | ChatGPT Learn](https://learn.chatgpt.com/docs/auth)
- [Agent approvals & security | ChatGPT Learn](https://learn.chatgpt.com/docs/agent-approvals-security)
- [Developer commands | ChatGPT Learn](https://learn.chatgpt.com/docs/developer-commands?surface=cli)
- [openai/codex — GitHub](https://github.com/openai/codex)
- [Codex CLI Install Guide — Arm Learning Paths](https://learn.arm.com/install-guides/codex-cli/)
- [codex: command not found? 7 Fixes for npm install -g @openai/codex — ofox.ai](https://ofox.ai/blog/codex-command-not-found-fix-npm-install-2026/)
- [How to Run Codex CLI on Windows: Native Install or WSL — CodeAgentSwarm](https://www.codeagentswarm.com/en/guides/codex-cli-on-windows)
