Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save minanagehsalalma/7d1b50926ba73923ca3ecddec29c728c to your computer and use it in GitHub Desktop.

Select an option

Save minanagehsalalma/7d1b50926ba73923ca3ecddec29c728c to your computer and use it in GitHub Desktop.
Installing OpenAI Codex CLI on Ubuntu 22.04 (VMware on Windows 11)

Installing OpenAI Codex CLI on Ubuntu 22.04 (VMware on Windows 11)

Complete troubleshooting guide — from a broken VM with no network to a working Codex CLI install.


Environment

  • Host OS: Windows 11
  • Hypervisor: VMware Workstation Pro
  • Guest OS: Ubuntu 22.04 LTS (Jammy)
  • Network Mode: NAT

Step 1 — Fix VMware Network Adapter (Host: Windows 11)

The VM's network adapter was disconnected. All commands run in PowerShell as Administrator.

1.1 Verify VMware services are running

Get-Service | Where-Object {$_.DisplayName -like "*VMware*"} | Select-Object DisplayName, Status, StartType

Ensure these are Running:

  • VMware Authorization Service
  • VMware DHCP Service
  • VMware NAT Service
  • VMware USB Arbitration Service

1.2 Restart NAT and DHCP services

Stop-Service "VMware NAT Service" -Force
Stop-Service "VMware DHCP Service" -Force
Start-Service "VMware DHCP Service"
Start-Service "VMware NAT Service"

1.3 Verify VMnet adapters are up

Get-NetAdapter | Where-Object {$_.InterfaceDescription -like "*VMware*"} | Select-Object Name, Status

Both VMnet1 and VMnet8 should show Up. If not, re-enable:

Get-NetAdapter | Where-Object {$_.InterfaceDescription -like "*VMware*"} | Enable-NetAdapter -Confirm:$false

1.4 Reset VMware virtual network (if adapter still broken)

Start-Process "C:\Program Files (x86)\VMware\VMware Workstation\vmnetcfg.exe" -Verb RunAs

Inside the editor: Change Settings → Restore Defaults → OK


Step 2 — Fix Network Interface Inside Ubuntu (Guest)

2.1 Find the correct interface name

ip link show

Interface will be something like ens33 (not ens160 as expected).

2.2 Bring the interface up and get an IP

sudo ip link set ens33 up && sudo dhclient ens33

2.3 Fix DNS — unlock resolv.conf and set Google DNS

The file was made immutable earlier. Unlock and rewrite it:

sudo chattr -i /etc/resolv.conf
printf "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" | sudo tee /etc/resolv.conf

2.4 Fix hostname resolution (sudo warnings)

echo "127.0.1.1 MyPC" | sudo tee -a /etc/hosts

2.5 Make DNS persistent across reboots

sudo tee /etc/systemd/resolved.conf > /dev/null <<EOF
[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1
EOF
sudo systemctl restart systemd-resolved

2.6 Make network interface auto-connect on boot

printf "network:\n  version: 2\n  ethernets:\n    ens33:\n      dhcp4: true\n" | sudo tee /etc/netplan/99-ens33.yaml
sudo netplan apply

2.7 Verify internet is working

ping -c 3 google.com

Step 3 — Install curl and Node.js

3.1 Install curl

sudo apt update && sudo apt install curl -y

3.2 Install Node.js 22.x

curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt install nodejs -y

3.3 Verify

node --version   # v22.x.x
npm --version    # 10.x.x

Step 4 — Install Codex CLI

4.1 Fix npm global permissions (avoid using sudo with npm)

mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

4.2 Install Codex CLI globally

npm install -g @openai/codex

4.3 Verify installation

codex --version

Step 5 — Launch Codex CLI

export OPENAI_API_KEY=your-api-key-here
codex

To make the API key permanent:

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

Summary of Root Causes

Problem Root Cause Fix
No internet in VM VMware network adapter was disconnected Enabled in VMware Settings + restored VMnet defaults
ens160 not found Interface renamed to ens33 after VMware reset Used ip link show to find correct name
DNS failure systemd-resolved not configured with upstream DNS Wrote Google DNS to /etc/resolv.conf + resolved.conf
resolv.conf kept reverting File locked with chattr +i Unlocked with chattr -i
sudo hostname warning MyPC not in /etc/hosts Added 127.0.1.1 MyPC to /etc/hosts
npm EACCES error Global npm dir owned by root Redirected global prefix to ~/.npm-global

Tested on Ubuntu 22.04 LTS (Jammy) in VMware Workstation Pro on Windows 11, April 2026.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment