WSL
使用 WSL2 时,Codex 会在 Linux 环境中运行,而不是使用原生的 Windows 沙箱。如果你需要 Linux 原生工具,你的代码仓库和开发工作流已经位于 WSL2 中,或者你的环境无法使用任何一种原生 Windows 沙箱模式,请选择 WSL2。
Codex 0.114 之前支持 WSL1。从 Codex 0.115 开始,Linux 沙箱迁移到了 bubblewrap,因此不再支持 WSL1。
从 WSL 内部启动 VS Code
Section titled “从 WSL 内部启动 VS Code”有关分步说明,请参阅 VS Code 官方 WSL 教程。
- 已安装 WSL 的 Windows。要安装 WSL,请以管理员身份打开 PowerShell,然后运行
wsl --install(Ubuntu 是常见选择)。 - 已安装 WSL 扩展 的 VS Code。
从 WSL 终端打开 VS Code
Section titled “从 WSL 终端打开 VS Code”# From your WSL shellcd ~/code/your-projectcode .这会打开一个 WSL 远程窗口,并在需要时安装 VS Code Server,同时确保集成终端在 Linux 中运行。
确认你已连接到 WSL
Section titled “确认你已连接到 WSL”-
查找显示
WSL: <distro>的绿色状态栏。 -
集成终端应显示 Linux 路径(例如
/home/...),而不是C:\。 -
你可以运行以下命令进行验证:
Terminal window echo $WSL_DISTRO_NAME此命令会打印你的发行版名称。
如果你在状态栏中看不到“WSL: …”,请按下 Ctrl+Shift+P,选择 WSL: Reopen Folder in WSL,并将代码仓库保存在 /home/... 下(而不是 C:\),以获得最佳性能。
如果 Windows 应用或项目选择器中没有显示你的 WSL 代码仓库,请在文件选择器或资源管理器中输入 \\wsl$,然后导航到你的发行版主目录。
在 WSL 中使用 Codex CLI
Section titled “在 WSL 中使用 Codex CLI”在提升权限的 PowerShell 或 Windows Terminal 中运行以下命令:
# Install default Linux distribution (like Ubuntu)wsl --install
# Start a shell inside Windows Subsystem for Linuxwsl然后在 WSL shell 中运行以下命令:
# Install and run Codex in WSLcurl -fsSL https://chatgpt.com/codex/install.sh | shcodex在 WSL 中处理代码
Section titled “在 WSL 中处理代码”-
在
/mnt/c/...等 Windows 挂载路径下工作,速度可能比在 Windows 原生路径下更慢。请将代码仓库放在 Linux 主目录下(例如~/code/my-app),以获得更快的 I/O,并减少符号链接和权限问题:Terminal window mkdir -p ~/code && cd ~/codegit clone https://github.com/your/repo.gitcd repo -
如果需要从 Windows 访问文件,可以在资源管理器的
\\wsl$\Ubuntu\home\<user>下找到它们。
故障排除和常见问题
Section titled “故障排除和常见问题”在 WSL 中,大型代码仓库运行缓慢
Section titled “在 WSL 中,大型代码仓库运行缓慢”-
确保你不是在
/mnt/c下工作。将代码仓库移动到 WSL 中(例如~/code/...)。 -
如有需要,请增加 WSL 的内存和 CPU;将 WSL 更新到最新版本:
Terminal window wsl --updatewsl --shutdown
WSL 中的 VS Code 找不到 codex
Section titled “WSL 中的 VS Code 找不到 codex”确认二进制文件存在,并且已在 WSL 内部的 PATH 中:
which codex || echo "codex not found"如果找不到该二进制文件,请参阅 Codex CLI 设置说明。