AI how-to notes · 2026-09-17 · last run 2026-09-17 · 한국어 원문
Installing Codex CLI in WSL (Ubuntu) — the trap where the Windows codex wins, measured up to the login step
One line summary
On our PC, which already had Codex CLI installed on Windows, WSL Ubuntu resolved codex to the Windows copy, and codex --version ended with a Missing optional dependency @openai/codex-linux-x64 error. Installing separately inside WSL and putting that path first on PATH gave the correct result.
Who this is for
- Anyone using codex on Windows via
npm install -g @openai/codexwho now wants it in WSL too - Anyone who types
codexin WSL and gets an error out of acodex.jsunder/mnt/c/...
Test environment
| Item | Value |
|---|---|
| Host OS | Windows 11 Home (10.0.26200) |
| WSL | WSL2, distro Ubuntu (state before start: Stopped) |
| Distro | Ubuntu 26.04 LTS (Resolute Raccoon), kernel 6.18.33.2-microsoft-standard-WSL2 |
| node / npm (WSL) | /usr/bin/node v22.22.1, /usr/bin/npm 9.2.0 |
| nvm | no ~/.nvm folder (we did not check for installs elsewhere) |
| codex on the Windows side | codex-cli 0.153.4 (C:\Users\User\AppData\Roaming\npm) |
| Version installed | @openai/codex 0.154.0 (latest per npm view that day) |
Commands inside WSL were run from Windows as wsl.exe -d Ubuntu -- bash -lc '...'. The code blocks below shorten that to wsl.
1. Check the distro and node first
wsl -l -v
wsl -d Ubuntu -- bash -lc 'cat /etc/os-release; uname -r'
wsl -d Ubuntu -- bash -lc 'command -v node; node --version; command -v npm; npm --version'The Ubuntu on this PC already had node v22.22.1 and npm 9.2.0 in /usr/bin, so we skipped the node setup step. On a distro without node you would have to get node in place here, and we did not run through that (see "What we did not test" below).
2. Before installing, see where codex resolves
This is the heart of the note.
wsl -d Ubuntu -- bash -lc 'which -a codex'/mnt/c/Users/User/AppData/Roaming/npm/codexPrinting this PC's WSL PATH showed 27 entries starting with /mnt/c, and /mnt/c/Users/User/AppData/Roaming/npm (the Windows global npm folder) was among them. That's why which finds a Windows file even though codex was never installed inside WSL.
That file is an sh script npm generated, so WSL can indeed run it. But running this install from WSL ended with an error about a missing Linux optional dependency.
Error: Missing optional dependency @openai/codex-linux-x64. Reinstall Codex: npm install -g @openai/codex@latest
at findCodexExecutable (file:///mnt/c/Users/User/AppData/Roaming/npm/node_modules/@openai/codex/bin/codex.js:107:9)The exit code was 1. The error suggests reinstalling with npm install -g. We did not try reinstalling on the Windows side; we solved it instead by installing a Linux copy inside WSL.
3. Install inside WSL
To keep the PC untouched, this round installed into a temp folder under the home directory.
wsl -d Ubuntu -- bash -lc 'mkdir -p ~/longtail_tmp/prefix && cd ~/longtail_tmp && npm install --prefix ~/longtail_tmp/prefix @openai/codex@latest'added 2 packages in 7sThe two packages installed were codex and codex-linux-x64. The codex-linux-x64 package came along with the WSL temp install.
prefix@ /home/<user>/longtail_tmp/prefix
└── @openai/codex@0.154.0If you actually mean to keep using it, npm install -g @openai/codex is the usual route. This PC's WSL global npm folder, per npm config get prefix, was /home/<user>/.npm-global, under the user's home. We did not run the global install this round.
4. Fix the PATH order and check the version
wsl -d Ubuntu -- bash -lc 'PATH="$HOME/longtail_tmp/prefix/node_modules/.bin:$PATH"; which -a codex; codex --version < /dev/null'/home/<user>/longtail_tmp/prefix/node_modules/.bin/codex
/mnt/c/Users/User/AppData/Roaming/npm/codex
codex-cli 0.154.0which -a now lists two. The WSL install at the top is the one that ran, and the version came back as the 0.154.0 we put in WSL. Switching to a global install only moves the same question around — which folder comes first on PATH — so after installing, checking the order with which -a codex is the safe move (we did not run the global-install case).
5. Up to, but not including, login
wsl -d Ubuntu -- bash -lc '~/longtail_tmp/prefix/node_modules/.bin/codex login status < /dev/null'Not logged inThe exit code was 1. The freshly installed codex in WSL reported Not logged in. How to check login state is written up separately in Checking Codex CLI login status. We did not run codex login in this note.
Results
| Check | Result |
|---|---|
which codex in WSL before installing | /mnt/c/Users/User/AppData/Roaming/npm/codex (the Windows one) |
codex --version in that state | Missing optional dependency @openai/codex-linux-x64, exit code 1 |
| Install inside WSL | added 2 packages in 7s (@openai/codex@0.154.0) |
codex --version after putting it first on PATH | codex-cli 0.154.0 |
codex login status (WSL) | Not logged in, exit code 1 |
codex --version on the Windows side (before the test) | codex-cli 0.153.4 |
What failed
codex --versionbefore installing failed as shown above. That is the symptom this note is about.- Our first attempt passed
export PATH=$HOME/...:$PATHwithout quotes and produced a stream ofexport: ... not a valid identifiererrors, because the Windows PATH mixes in paths with spaces such asProgram Files. We re-ran it wrapped in double quotes, asPATH="$HOME/...:$PATH". - After running
codex --versionfrom the WSL install, we found a~/.codex/tmp/arg0/folder in the WSL home. The creation time on~/.codexwas recorded as 17:24:57, in the same window as that first run. We deleted the temp install folder~/longtail_tmpand left~/.codexin place.
What we did not test
- We did not run through getting node in place (apt, nvm and so on) on a distro without it. This PC already had node.
- We did not run a WSL global install with
npm install -g. - We did not run
codex loginor any prompt after logging in. We also did not check how browser login opens from WSL. - We did not try the
/etc/wsl.confsetting that turns off appending the Windows PATH. This PC'swsl.confhad only[user]and[boot]sections. - We did not check distros other than Ubuntu 26.04, or WSL1.