> ## Content Index
> Fetch the complete content index at: https://www.winsolvetech.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# OpenAI Codex WSL Setup on Windows, Step by Step
- URL: https://www.winsolvetech.com/openai-codex-wsl-setup-windows/
- Published: 2026-10-11T09:13:05.000Z
- Updated: 2026-10-11T09:13:04.000Z
- Author: MD Syful Islam Rasel
- Tags: Windows 11, Troubleshooting

If you want OpenAI [Codex on a Windows](https://www.winsolvetech.com/set-up-ai-tools-windows/) machine, the right place to run it is inside WSL2, not in Windows PowerShell. WSL2 gives Codex the Linux shell and filesystem it expects, which avoids most path and dependency problems. You’ll need WSL2, a Linux distro such as Ubuntu, your project in the Linux filesystem, and your OpenAI access set up inside that same WSL shell.

## What you need before you start

- A Windows version that supports WSL2\. On current Windows 10 and Windows 11 builds, that usually means a recent fully updated system.
- Virtualization enabled in firmware. If WSL2 won’t start, this is one of the first things to check in BIOS or UEFI settings.
- WSL2, not WSL1\. Codex is much more likely to behave correctly in WSL2 because it uses a real Linux kernel layer.
- A Linux distro installed in WSL, with Ubuntu being the safest default choice for most people.
- An OpenAI account and whatever access token or API key your Codex setup uses.
- A project repository you can open from inside WSL.

If you already have WSL installed, check that it’s actually version 2 and that your distro is running there, not version 1\. A lot of setup trouble comes from assuming WSL is on when only the feature is enabled, or from using a distro that was created before WSL2 was turned on.

One more practical point: keep the repo in the Linux filesystem, such as under your WSL home directory, instead of working from `C:\` through `/mnt/c/`. That avoids many file-watching, permission, and performance problems later.

## Install WSL2 and a Linux distro

1. Open PowerShell as Administrator on Windows.

```powershell
wsl --install
```

PowerShell (run as Administrator)

This usually enables the required Windows features, installs WSL, and sets up a default distro.

1. If WSL is already installed, make sure version 2 is the default.

```powershell
wsl --set-default-version 2
```

PowerShell (run as Administrator)

1. Install Ubuntu if it did not install automatically, or if you want to choose it explicitly.

```powershell
wsl --install -d Ubuntu
```

PowerShell (run as Administrator)

1. Reboot if Windows asks for it, then launch Ubuntu from the Start menu.

The first launch usually asks you to create a Linux username and password. That account is separate from your Windows login.

1. Confirm that your distro is on WSL2.

```powershell
wsl -l -v
```

PowerShell

You want to see your distro listed with version `2`.

If virtualization is off in firmware, WSL2 may install but not run correctly. If the distro starts slowly, fails to launch, or reports a kernel-related issue, check firmware virtualization and Windows features before you keep going.

If you prefer a different Linux distro, that is usually fine as long as it is supported by WSL2 and has the shell tools Codex expects. Ubuntu is still the least surprising choice because most install instructions assume it.

## Open your project inside WSL, not Windows

Codex tends to behave better when the code lives in the Linux filesystem. That means opening the repository from inside Ubuntu or another WSL shell, not from Windows Explorer with a path on `C:\` and then hoping Linux tools handle it well.

1. Open your WSL distro.

```bash
cd ~
```

Linux shell

1. Create a project folder inside Linux if your repo is new.

```bash
mkdir -p ~/projects
cd ~/projects
```

Linux shell

1. If the repo already exists in Windows, copy or clone it into WSL.

```bash
git clone <your-repo-url>
```

Linux shell

1. If you need to reach a Windows file temporarily, use `/mnt/c/`, but don’t keep the main repo there.

A repo stored under your WSL home directory usually gives you better file watching and fewer path surprises. If a command later says it cannot find files, the first thing to check is the repo location.

If you use VS Code, opening the folder through WSL is the right pattern. Start from the WSL terminal, move into the repo, and open the folder from there so the editor attaches to the Linux side of the environment.

## Install Codex in the WSL shell

Install Codex from inside the WSL terminal, not from Windows PowerShell. That keeps the binary, its dependencies, and its configuration in the same Linux environment where it will run.

1. Update package metadata inside WSL first.

```bash
sudo apt update
```

Linux shell

1. Install the basic tools Codex commonly needs, especially if your distro is minimal.

```bash
sudo apt install -y git curl ca-certificates build-essential
```

Linux shell

1. Install Codex using the method from the Codex release you are following.

If the installer is distributed as a shell command, run it here in the WSL terminal. If it is distributed through a package manager such as `npm`, `pipx`, or another tool, install it here as well. The key point is that the command runs in Linux, not in PowerShell.

1. Confirm the command is on your WSL `PATH`.

```bash
codex --help
```

Linux shell

If the command name is different in the release you are using, run that exact name instead. The expected result is a help screen or usage output, not a `command not found` error.

If the installer places the binary in a directory that is not on `PATH`, add that directory to your WSL shell profile, not to Windows environment variables. Keep the setup on the Linux side so the terminal you actually use can find it.

## Set up your OpenAI access key

Set the OpenAI key inside WSL so Codex can authenticate from the Linux shell without depending on Windows tools.

1. Open the shell profile for the WSL user you plan to use.

```bash
nano ~/.bashrc
```

Linux shell

1. Add an export line for the key, replacing the placeholder value with your real secret.

```bash
export OPENAI_API_KEY="your_key_here"
```

Linux shell

1. Save the file and load it into the current shell.

```bash
source ~/.bashrc
```

Linux shell

1. Check that the variable is visible in WSL.

```bash
echo "$OPENAI_API_KEY"
```

Linux shell

You should see the value echoed back in the WSL terminal.

If your Codex build uses a login flow instead of a raw API key, do that login from inside WSL as well. The point is the same: credentials should live in the Linux environment that is running Codex, not in a Windows terminal session that happens to call into WSL.

Do not paste your key into Windows shell profiles, shared repo files, or scripts that may be committed to git. Keep it in your WSL user environment or in the mechanism the Codex release expects.

If you use a secret manager or `.env` file, make sure the file stays outside version control and is read by the WSL process, not by a Windows wrapper.

## Run a first test prompt

The first test should be small and safe. You are checking three things at once: Codex runs, it can authenticate, and it can see the repo from WSL.

1. Move into the root of your project in WSL.

```bash
cd ~/projects/<your-repo>
```

Linux shell

1. Run a harmless help or inspection command first if your Codex tool provides one.

```bash
codex --help
```

Linux shell

1. Run a simple prompt or task that only asks Codex to inspect the repo, not to make destructive changes.

For example, ask it to summarize the top-level files or point out the main language used in the project. If your Codex CLI takes a prompt argument, use a short request like that from inside the repo directory.

1. Confirm the response mentions files that actually exist in the repository.

If the command returns output and the output matches the codebase you opened, the setup is working. If it can run but cannot see files, the issue is usually path-related rather than authentication-related.

A good first pass is something that reads the project without editing it. Once that works, you can try a small code suggestion or a limited refactor.

## If Codex is slow or can’t see files

Most WSL problems come from a small set of causes.

If Codex is slow, check where the repo lives. Projects under `/mnt/c/` are often slower and less predictable than projects under the WSL home directory. Move the repo into Linux storage and try again.

If Codex can’t see files, confirm you are in the repo root in WSL and not in a Windows path that was opened from PowerShell. Run `pwd` in the WSL shell and make sure it points to a Linux path such as `/home/yourname/...`.

If Codex says a dependency is missing, install it inside WSL with the distro package manager. For example, many tools expect `git`, `curl`, `ca-certificates`, and a compiler toolchain to exist. Add other packages only as the command output tells you to.

If the terminal itself cannot find Codex, check `PATH` in the WSL shell. A command installed in Windows will not automatically appear in Ubuntu. Install it again inside WSL if needed.

If the repo was cloned in Windows and opened from WSL, line endings, permissions, and watcher behavior can all get weird. The simplest fix is usually to clone or copy the project directly into the Linux filesystem and work there.

If WSL2 feels outdated or unstable, update it and the distro before blaming Codex. Old WSL builds can cause strange shell and filesystem behavior that looks like a Codex problem but isn’t.

## Keeping the setup stable over time

Once it works, keep Windows, WSL, and the distro current so the environment does not drift too far apart.

Update WSL from PowerShell when Windows offers changes or fixes.

```powershell
wsl --update
```

PowerShell

Update your Linux package lists and installed packages from inside WSL on a regular basis.

```bash
sudo apt update
sudo apt upgrade
```

Linux shell

If your Codex installer has its own update command, run that in WSL too, using the same shell you used for installation. That keeps the binary and its dependencies aligned with the environment that launches it.

When you make changes to your shell profile, reload the shell or open a new WSL window so the updated `PATH` and environment variables take effect.

If you switch distros, reset the environment, or reinstall WSL, expect to repeat the Linux-side setup: install the distro, install Codex in WSL, add the key in WSL, then recheck with a simple prompt. The Windows machine can stay the same, but the Linux side still needs to be ready each time.

## Conclusion

If you keep Codex inside WSL2, open the repo from the Linux filesystem, and store the key in the WSL shell, the setup usually stays predictable. From there, your next step is to use it on a small task in the repo you actually care about, then expand to real edits once the command, authentication, and file access all check out. If something breaks later, start with the same three places: WSL version, repo location, and the shell where Codex was installed.

## Frequently Asked Questions

### Do I have to use Ubuntu for OpenAI Codex in WSL?

No. Ubuntu is just the safest default because most Linux instructions assume it. Any supported WSL2 distro should work if it has the tools Codex needs and you install everything inside that distro.

### Can I install Codex from Windows PowerShell and use it in WSL?

You usually should not. If the tool runs in WSL, install it in WSL so the binary, dependencies, and credentials all live in the same Linux environment.

### Should my project stay on C: drive or inside WSL?

For Codex, keep the repo inside the WSL Linux filesystem if you can. The Windows drive mount works for temporary access, but it often causes slower file access and more path friction.

### How do I know WSL2 is actually enabled?

Run \`wsl -l -v\` in PowerShell. If your distro shows version \`2\`, you are on WSL2.