Skip to main content

Codex Local Installation Guide

Using an Ubuntu 24.04 LTS instance

image

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

image

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

image

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

image

Load:

source ~/.bashrc

Verify:

nvm -v

image

Set up a domestic Node mirror

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

image

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

image

Install Codex CLI

Install via npm:

Officially supported:

npm install -g @openai/codex

After installation:

codex --version

image

Start:

codex

image

Codex official documentation: