🚀 How I Successfully Installed and Fixed the OpenAI Codex CLI on Ubuntu

After upgrading my Ubuntu system, I ran into several unexpected issues while trying to install and authenticate the OpenAI Codex CLI. This post walks through the complete solution — including the GPU-related crash in Chrome and the final setup that now works perfectly.

1. Background

The OpenAI Codex CLI allows developers to generate, explain, and edit code directly from the terminal using AI. However, after upgrading Ubuntu, the installation became unstable due to an outdated Node.js version, a keyring mismatch, and Chrome freezing during authentication.

2. The Initial Problems

  • Node.js was still on version 12.x — too old for the Codex CLI, which requires Node 16+
  • The GNOME Keyring password no longer matched my system password, blocking authentication
  • Chrome completely froze when trying to open the OAuth login window

3. Step-by-Step Fix

Step 1 – Clean up old Codex and Node installations

sudo npm uninstall -g codex codex-cli @openai/codex || true
sudo rm -f /usr/local/bin/codex
sudo apt purge -y nodejs npm
sudo apt autoremove -y

Step 2 – Install Node.js 20 (LTS)

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs build-essential
node -v
npm -v

Now Node.js and npm are up-to-date, and compatible with the latest OpenAI tools.

Step 3 – Install the OpenAI Codex CLI

sudo npm install -g @openai/codex

Step 4 – Fix GNOME Keyring Authentication

After the Ubuntu upgrade, my system password no longer matched the keyring password, causing the Codex login window to fail. I solved it by resetting the keyring:

cd ~/.local/share/keyrings
mv login.keyring login.keyring.bak
gnome-keyring-daemon --replace &

On the next login, Ubuntu automatically created a new keyring that matched my current password.

Step 5 – Fix Chrome GPU Crash

During OAuth login, Chrome repeatedly froze on Ubuntu Wayland. The simple fix was to disable GPU acceleration and the Ozone platform:

google-chrome --disable-gpu --disable-features=UseOzonePlatform

Step 6 – Authenticate the Codex CLI

Once Chrome opened properly, I completed the browser-based login and the Codex CLI connected successfully. If the login window still doesn’t open, you can authenticate using an environment variable instead:

export OPENAI_API_KEY="sk-your-api-key"
echo 'export OPENAI_API_KEY="sk-your-api-key"' >> ~/.bashrc
source ~/.bashrc

4. Final Result

After these steps, the Codex CLI works flawlessly on Ubuntu. Commands like the following now run smoothly:

codex "Write a Python script that lists all .log files in a directory."
# or
openai api completions.create -m gpt-4o-mini -p "Generate a Node.js HTTP server example."

5. Key Takeaways

  • Always use the latest LTS version of Node.js when working with OpenAI tools.
  • Reset your GNOME keyring if Ubuntu upgrades break authentication.
  • If Chrome freezes, launch it with --disable-gpu and --disable-features=UseOzonePlatform.
  • Environment variables are a reliable alternative to browser-based authentication.

✅ Working Environment

  • OS: Ubuntu 22.04 LTS (Jammy)
  • Node.js: v20.x LTS
  • Codex CLI: @openai/codex 0.45.0
  • Browser: Google Chrome Stable

💡 Conclusion

After fixing the Node.js version, resetting the keyring, and launching Chrome without GPU acceleration, the OpenAI Codex CLI now installs, logs in, and executes commands perfectly. This setup is stable, fast, and fully compatible with modern Ubuntu environments.

Comments