This guide shows how to install Codex CLI, OpenAI's coding agent, on Windows PowerShell, macOS, and Ubuntu, sign in with your ChatGPT account, and start your first task. It also covers how to update and uninstall it.
1. Requirements
- One of Windows 11, macOS 12 or later, or Ubuntu 20.04 or later (Windows 10 version 1809 or later may work, but it can be less stable than Windows 11)
- 4 GB of memory or more (8 GB recommended)
- A ChatGPT account (Plus, Pro, Business, Edu, or Enterprise plan) or an OpenAI API key
- Git 2.23 or later (not required, but recommended)
- An internet connection
You can install Codex CLI with a single install script, without Node.js. Node.js is needed only if you choose to install with npm (step 6).
2. Install on Windows (PowerShell)
Open a new PowerShell window from the Start menu and run the command below. You don't need administrator rights. -ExecutionPolicy ByPass lifts the script execution policy for this one run only; your computer's execution policy setting does not change.
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"The install script puts codex.exe in the %LOCALAPPDATA%\Programs\OpenAI\Codex\bin folder and adds that folder to your user PATH. When the installation finishes, it shows the installed version, such as Codex CLI 0.164.0 installed successfully., and asks whether to run it now.
To use codex in other PowerShell windows, close the window, open a new one, and then run it. Windows that were open before the installation cannot read the updated PATH.
codex3. Install on macOS
Open Terminal and run the install script. The script detects Apple Silicon (M1 and later) and Intel Macs by itself.
curl -fsSL https://chatgpt.com/codex/install.sh | shCodex is installed to ~/.local/bin/codex. If this folder is not in your PATH, the script adds a PATH line to your shell startup file (~/.zprofile for zsh, ~/.bash_profile for bash). When the installation finishes, open a new terminal and run it.
codexIf you use Homebrew, you can also install it with Homebrew.
brew install --cask codex4. Install on Ubuntu
Use the same install script as on macOS. Both x86_64 and arm64 are supported. The script downloads files with curl or wget, so if you don't have curl, install it first with sudo apt install curl.
curl -fsSL https://chatgpt.com/codex/install.sh | shCodex is installed to ~/.local/bin/codex, and if you use bash, a PATH line is added to ~/.bashrc. To use it right away in the terminal where you installed it, reload ~/.bashrc. There is no output. You can also close and reopen the terminal or reconnect over SSH.
source ~/.bashrccodex5. Check the installation
If running codex shows the OpenAI Codex box along with the model name and the current folder, it is installed. On the first run, the sign-in screen appears first (step 7). You can check your current sign-in status with the command below.
codex login statusIf you get an error saying the command cannot be found, the terminal was opened before the installation. Open a new terminal and run it again.
6. Install with npm (all three OSes)
If you already use Node.js, you can also install Codex with npm. The Codex npm package requires Node.js 16 or later. If you don't have Node.js, install it first by following the guide below.
- Windows: How to Install Node.js on Windows 11
- Ubuntu: How to Install Node.js with nvm on Ubuntu 24.04 (22.04, 26.04)
- macOS: Download the LTS installer from nodejs.org and install it.
npm install -g @openai/codex7. First run and sign-in
Go to the project folder you want to work in and run codex. On the first run, a screen appears where you choose how to sign in. If you choose Sign in with ChatGPT, a browser opens; after you sign in to ChatGPT, you return to Codex and can start using it right away. Codex usage comes out of the usage included in your ChatGPT plan.
cd ~/my-project
codexTo open the sign-in screen on its own, run codex login.
codex loginSign in with an API key
You can also use an OpenAI API key instead of a ChatGPT plan. In that case, you are billed at standard API rates on your OpenAI Platform account. With your API key stored in the OPENAI_API_KEY environment variable, pass the key to codex login as shown below. Because the key is not typed on the command line, it is not saved in your shell history.
printenv OPENAI_API_KEY | codex login --with-api-keySign in on a server without a browser
Where you can't open a browser, such as on an Ubuntu server you connect to over SSH, use device code sign-in (beta). First, turn on device code sign-in in your ChatGPT security settings (personal account) or workspace permissions (admin). When you run the command, a link and a one-time code are shown. Open the link in a browser on another PC, sign in, and enter the code.
codex login --device-authYour sign-in information is saved in the ~/.codex/auth.json file or in your operating system's credential store. auth.json contains access tokens, so do not commit it to a repository or send it to anyone.
8. Update
If you installed with the install script, run the same command you used to install it again to update to the latest version.
powershell -ExecutionPolicy ByPass -c "irm https://chatgpt.com/codex/install.ps1 | iex"curl -fsSL https://chatgpt.com/codex/install.sh | shIf you installed with Homebrew or npm, update with the commands below.
brew upgrade --cask codexnpm install -g @openai/codex9. Uninstall
First, remove your saved sign-in information.
codex logoutIf you installed with npm or Homebrew, use that package manager's uninstall command.
npm uninstall -g @openai/codexbrew uninstall --cask codexThere is no separate uninstall command for Codex installed with the install script. Delete the files the install script created. On macOS and Ubuntu, run the command below.
rm -f ~/.local/bin/codex ~/.local/bin/codex-code-mode-host
rm -rf ~/.codex/packages/standaloneIn Windows PowerShell, run the command below. You can remove the %LOCALAPPDATA%\Programs\OpenAI\Codex\bin entry that was added to your user PATH in Settings › System › About › Advanced system settings › Environment Variables.
Remove-Item -Recurse -Force "$env:LOCALAPPDATA\Programs\OpenAI\Codex"
Remove-Item -Recurse -Force "$env:USERPROFILE\.codex\packages\standalone"10. Troubleshooting
The codex command is not found after installation
A terminal that was open before the installation cannot read the newly added PATH. Close the terminal or PowerShell window, open a new one, and run it again. On Ubuntu, you can also run source ~/.bashrc.
I chose Sign in with ChatGPT on a remote server, but sign-in never finishes
Browser sign-in sends the result back to Codex through a localhost address. On a remote server or in an environment without a browser, this step is blocked. Sign in with codex login --device-auth from step 7. If you can't use device code sign-in, you can also sign in with codex login on a PC that has a browser and then copy the ~/.codex/auth.json file to the same location on the server.
I get a certificate error when signing in on a company network
This can happen when your company network inspects HTTPS with its own root certificate. Put the path to the company certificate (PEM file) in the CODEX_CA_CERTIFICATE environment variable, then run codex login again. A detailed record of the sign-in process is kept in the codex-login.log file in the log folder.
Sandbox setup fails on Windows
This happens when you declined the administrator prompt (UAC), or when company policy blocks creating local users or changing firewall rules. Run the setup again and click Yes in the administrator prompt. On a company PC, you may need to contact your IT team. For details, see the Windows guide in the official documentation.
Was this guide helpful? Let us know if anything is wrong or out of date.
Request a correction