Set Up OpenAI Codex on Linux
Install Codex CLI and sign in on a Linux VPS.
Set up OpenAI Codex on Linux
OpenAI Codex is an AI-powered coding agent that works directly from your terminal. It can inspect project files, explain unfamiliar code, create and modify files, run terminal commands, troubleshoot errors, and help complete software development tasks.
Unlike the regular ChatGPT website, Codex CLI works inside your Linux environment. This allows it to understand the files and tools available on your system and assist with real development projects.
Codex CLI can be installed on:
- Linux desktop computers
- Linux VPS servers
- Development servers
- Remote systems accessed through SSH
- Windows systems using WSL
Codex CLI
The command-line version of Codex is officially called Codex CLI. It is not a separate Linux version of the ChatGPT desktop application.
What Codex can do
Codex can assist with tasks such as:
- Explaining an existing codebase
- Creating scripts and applications
- Finding and fixing errors
- Editing configuration files
- Running tests
- Reviewing code changes
- Installing project dependencies
- Refactoring code
- Writing documentation
- Working with Git repositories
- Running repeatable tasks from scripts or CI/CD systems
Codex works inside the directory from which it is launched. For example, when Codex is started inside a website project, it can inspect and work with the files belonging to that website.
Review commands and changes
Codex may be able to create files, modify files, and execute terminal commands. Always review proposed commands and changes before approving them, especially when running Codex as the root user.
Before you begin
Before installing Codex, make sure you have:
- A Linux system or Linux VPS
- Terminal or SSH access
- An active internet connection
- A ChatGPT account
curlinstalled
This tutorial uses Ubuntu 24.04. However, the Codex installer can also be used on many other Linux distributions.
Install and sign in
Connect to your Linux server
Connect to your VPS through SSH:
ssh root@YOUR_SERVER_IP
Replace YOUR_SERVER_IP with the IP address of your VPS.
Enter the server password when requested.
Update the system
Update the available package information:
apt update
Optionally, install the latest available package updates:
apt upgrade -y
Install curl and Git
Install curl, Git, and the required certificate package:
apt install curl git ca-certificates -y
curl is used to download the Codex installer, while Git is useful when Codex is working with software projects and repositories.
Check that both programs are available:
curl --version
git --version
Install Codex CLI
Run the official OpenAI Codex installation command:
curl -fsSL https://chatgpt.com/codex/install.sh | sh
The installer downloads and installs the Codex CLI for your Linux system.
After the installation has finished, reload your shell:
exec "$SHELL" -l
Alternative
Alternatively, you can disconnect from the SSH session and reconnect to the server.
Verify the installation
Check whether Codex was installed successfully:
codex --version
You should receive output containing the installed Codex CLI version.
You can also locate the Codex executable with:
command -v codex
Sign in to Codex
Codex supports two main authentication methods:
- Sign in with a ChatGPT account
- Sign in with an OpenAI API key
Using a ChatGPT account is generally the easiest option for individual users.
Sign in with ChatGPT
Start the login process:
codex login
Codex will provide instructions for signing in with your ChatGPT account.
Sign in on a headless VPS
A VPS normally does not have its own web browser. In this situation, use device-code authentication:
codex login --device-auth
Codex will display:
- A website address
- A temporary one-time code
Open the displayed website on your own computer, sign in to ChatGPT, and enter the one-time code.
Device-code authentication
Device-code authentication may need to be enabled in your ChatGPT security settings or by your organization's ChatGPT workspace administrator.
After authentication has been approved, return to the VPS terminal.
Check the authentication status:
codex login status
You have now installed and signed in to OpenAI Codex on your Linux VPS.
What's next?
Continue with Getting started with Codex CLI for common commands and safe workflows.