Codex Local Installation Guide
Using an Ubuntu 24.04 LTS instance

Switch to the Alibaba Cloud mirror
Back up the sources
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
Edit:
sudo vim /etc/apt/sources.list
Replace with:
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
Save:
:wq

Update:
sudo apt update
sudo apt upgrade -y
Install basic tools
sudo apt install -y \ curl \ wget \ git \ vim \ build-essential \ ca-certificates \ jq \ tmux \ tree
Verify:
git --version

Install Node.js (for users in mainland China)
Codex CLI depends on Node.js.
1. Install nvm (optimized for mainland China)
Run:
curl -fsSL -o- https://gitee.com/mirrors/nvm/raw/v0.40.1/install.sh | bash

Load:
source ~/.bashrc
Verify:
nvm -v

Set up a domestic Node mirror
- Write the mirror configuration
echo 'export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node' >> ~/.bashrc
- Apply the changes
source ~/.bashrc
- Load nvm (if not loaded yet)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
- Install Node.js (it will use the domestic mirror)
nvm install 22
- Verify
node -v
npm -v

Configure the npm domestic mirror
Check:
npm config get registry
Change:
npm config set registry https://registry.npmmirror.com
Verify:
npm config get registry
Result:
https://registry.npmmirror.com

Install Codex CLI
Install via npm:
Officially supported:
npm install -g @openai/codex
After installation:
codex --version

Start:
codex

Codex official documentation: