Skip to content

Instantly share code, notes, and snippets.

@simonholm
Created September 21, 2025 16:45
Show Gist options
  • Select an option

  • Save simonholm/747bea0793a0e4f46f6808915e2e86d8 to your computer and use it in GitHub Desktop.

Select an option

Save simonholm/747bea0793a0e4f46f6808915e2e86d8 to your computer and use it in GitHub Desktop.

Running OpenAI Codex CLI in Termux (Android, aarch64)

Problem

  • The official npm package (@openai/codex) ships prebuilt binaries (codex-aarch64-unknown-linux-musl).

  • Android’s Bionic libc rejects them with:

    error: "…/codex-aarch64-unknown-linux-musl" has unexpected e_type: 2

  • Result: the CLI doesn’t launch in Termux.


Solution: Build from Rust Source

Codex has a Rust rewrite. You can compile it directly in Termux and run it natively.

1. Install prerequisites

pkg install rust git clang make

2. Clone the repo

git clone https://github.com/openai/codex.git
cd codex/codex-rs/cli

3. Build a debug binary (lighter, works without swap)

cargo build

Binary appears at:

~/codex/codex-rs/target/debug/codex

4. Replace the broken npm binary

rm $PREFIX/bin/codex
ln -s ~/codex/codex-rs/target/debug/codex $PREFIX/bin/codex

5. Run it

codex --help
codex

You’ll see the Codex splash screen and login prompt. ✅


For a Faster Release Build

The optimized --release build needs more memory than most phones have.
You must enable swap before compiling.

1. Create a 4 GB swapfile (only once)

fallocate -l 4G ~/swapfile
chmod 600 ~/swapfile
mkswap ~/swapfile

(If fallocate is missing: dd if=/dev/zero of=~/swapfile bs=1M count=4096)

2. Enable it before compiling

swapon ~/swapfile

Check with:

free -h

3. Build release binary

cd ~/codex/codex-rs/cli
cargo build --release -j1

Binary appears at:

~/codex/codex-rs/target/release/codex

4. Disable swap (optional after build)

swapoff ~/swapfile

Takeaway

  • The npm package doesn’t work on Android.
  • Compiling from source in Termux gives you a working native Codex CLI.
  • Debug build is fine for testing; release build needs swap to finish.
  • Once linked, the CLI behaves just like on Linux/macOS — login, API key, sandboxed execution — all from your phone. 😎
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment