This repository provides Setup-Codex.ps1, a one-time PowerShell script that installs Node.js 22 and the @openai/codex CLI inside your default Ubuntu WSL instance, then adds a PowerShell wrapper so you can run codex from any Windows folder.
- Windows 10/11 with WSL 2 enabled and an Ubuntu distro installed as the default.
- PowerShell (Windows PowerShell 5.1 or PowerShell 7+).
- Internet access for apt,curl, andnpmdownloads.
Tip: Run
wsl --statusin PowerShell to confirm WSL is installed and Ubuntu is the default distribution before starting.
- Download or clone this repository so that Setup-Codex.ps1is on your machine.
- Open a new non-admin PowerShell window in the folder that contains the script.
- Allow the script to run in the current session (if execution policy blocks it):
Set-ExecutionPolicy -Scope Process Bypass 
- Execute the installer:
.\Setup-Codex.ps1
- Restart PowerShell (or open a new window) and run codex --versionfrom any Windows path to confirm the wrapper works.
The script is idempotent — re-run it any time you want to upgrade Codex or refresh the wrapper.
- Removes any existing Windows-side codexshims under%AppData%\npm.
- Ensures curl,ca-certificates,gnupgare present in Ubuntu.
- Installs Node.js 22 via NodeSource packages (no NVM), and installs @openai/codexglobally.
- Injects a codexfunction into your PowerShell profile that transparently forwards calls into WSL with the correct working directory.
- Reloads your PowerShell profile and prints a quick status check.
- From any Windows folder, run codexand the command will execute inside Ubuntu WSL.
- Inside WSL you can manage Codex with npmas usual (e.g.,npm update -g @openai/codex).
- The wrapper function lives inside your PowerShell profile ($PROFILE) between# BEGIN/END CODEX WSL WRAPPER. You can remove or adjust it later if needed.
- WSL not installed: The script stops if wsl --statusfails. Follow the WSL installation guide and ensure Ubuntu is the default distribution.
- sudoprompts: Package installs inside Ubuntu require your Linux user password. Enter it when prompted.
- Missing profile directory: The script creates the profile file automatically, but PowerShell must have permission to write to it. If it fails, check $PROFILE.
- codexnot found afterwards: Open a new PowerShell window so the updated profile loads, or run- . $PROFILEmanually. If you installed a different WSL distro than Ubuntu as default, the wrapper targets your default distro automatically.
- Proxy or firewall issues: curl,apt, ornpmmight need proxy configuration. Configure your environment variables accordingly before re-running the script.
Need to undo the wrapper? Remove the # BEGIN CODEX WSL WRAPPER block from your PowerShell profile and delete any global Codex install inside Ubuntu (sudo npm uninstall -g @openai/codex).
- Setup-CodexWSL.ps1and- Setup-DevPS-CodexWrapper.ps1are deprecated and now delegate to- Setup-Codex.ps1for a unified flow.