Windows + WSL2 (Ubuntu24.04)安装 Codex

📅 2026/6/26 23:31:50
Windows + WSL2 (Ubuntu24.04)安装 Codex
Windows WSL2 安装 Codex 操作笔记环境Windows 11 WSL2 Ubuntu 24.04目标在 WSL2 Ubuntu 中安装和运行 Codex CLIWindows 只负责 VS Code 图形界面。一、最终推荐工作方式以后日常使用流程cd~/workspace/你的项目 code.codex含义项目文件放在 Ubuntu / WSL2 里Windows 上的 VS Code 只是查看和编辑文件Codex 实际运行在 Ubuntu 命令行中代码生成、文件修改、项目校验都在 WSL2 里完成二、检查 WSL2 是否正常在 Windows PowerShell 执行wsl-l-v正常结果类似NAME STATE VERSION Ubuntu-24.04 Running 2如果不是 VERSION 2执行wsl--set-versionUbuntu-24.04 2进入 Ubuntuwsl-d Ubuntu-24.04三、WSL2 本地代理提示说明启动 Ubuntu 时可能出现wsl: 检测到 localhost 代理配置但未镜像到 WSL。 NAT 模式下的 WSL 不支持 localhost 代理。这不是严重报错意思是Windows 里的代理地址一般是127.0.0.1:7890但在 WSL2 NAT 模式下Ubuntu 里的127.0.0.1指的是 Ubuntu 自己不是 Windows所以代理不能自动复用。四、WSL2 代理推荐配置方式方式一开启 mirrored 网络模式在 Windows PowerShell 执行notepad$env:USERPROFILE\.wslconfig写入[wsl2] networkingModemirrored dnsTunnelingtrue autoProxytrue firewalltrue保存后执行wsl--shutdown wsl-d Ubuntu-24.04测试网络curl-Ihttps://chatgpt.com方式二手动给 WSL 设置代理先在 Windows 代理软件里打开允许局域网连接 / Allow LAN然后在 Ubuntu 里执行hostip$(iproute|awk/default/ {print $3})exporthttp_proxyhttp://$hostip:7890exporthttps_proxyhttp://$hostip:7890exportHTTP_PROXY$http_proxyexportHTTPS_PROXY$https_proxy测试curl-Ihttps://chatgpt.com看到类似HTTP/1.1 200 Connection established说明 WSL 已经能通过代理访问外网。如果后面出现HTTP/2 403 cf-mitigated: challenge server: cloudflare这通常是 Cloudflare 拦截命令行访问网页首页不代表代理失败。五、安装基础依赖在 Ubuntu 里执行sudoaptupdatesudoaptupgrade-ysudoaptinstall-ycurlgitca-certificates build-essentialunzipzipjq bubblewrap六、创建 Codex 工作目录建议统一把项目放在~/workspace创建测试项目mkdir-p~/workspace/codex-democd~/workspace/codex-demogitinit不建议直接在这些目录运行 Codex/mnt/c/Users/你的用户名/Desktop /mnt/d/公司资料 /mnt/d/投标文件 /mnt/d/微信文件正式文件建议复制副本到 WSL 工作区再让 Codex 操作。七、安装 Codex CLI你本次使用的是 standalone installer 安装方式curl-fsSLhttps://chatgpt.com/codex/install.sh|sh安装后检查版本whichcodex codex--version当前结果/home/muxia/.local/bin/codex codex-cli 0.142.0这说明 Codex 安装在当前 Ubuntu 用户目录下不是 npm 全局安装。八、启动 Codex进入项目目录cd~/workspace/codex-demo codex首次启动按提示登录 ChatGPT 账号。测试命令查看当前文件夹下的文件九、VS Code 配置 WSL在 Ubuntu 项目目录里执行code.这会打开 Windows 上的 VS Code但实际编辑的是 WSL2 里的文件。VS Code 左下角应显示类似WSL: Ubuntu-24.04十、VS Code 设置 Codex 使用 WSL在 VS Code 中按Ctrl Shift P搜索Preferences: Open User Settings (JSON)加入{chatgpt.runCodexInWindowsSubsystemForLinux:true}如果已有其他配置注意加逗号。十一、Codex 配置 GPT-5.5 high配置文件位置~/.codex/config.toml编辑nano~/.codex/config.toml当前推荐配置model gpt-5.5 model_reasoning_effort high [projects./mnt/d/soft/coding/workspace/codex-demo] trust_level trusted [projects./home/muxia] trust_level trusted [tui] status_line [ model-with-reasoning, context-remaining, current-dir, git-branch, five-hour-limit, weekly-limit, codex-version ] [tui.model_availability_nux] gpt-5.5 1保存方式Ctrl O 回车 Ctrl X十二、底部状态栏说明配置成功后Codex 底部会显示类似gpt-5.5 high · Context 99% left · /mnt/d/soft/coding/workspace/codex-demo · master · 5h 98% left · weekly 98% …含义gpt-5.5 high当前模型和推理强度Context 99% left当前会话上下文剩余 99%/mnt/d/.../codex-demo当前工作目录master当前 Git 分支5h 98% left5 小时窗口额度还剩约 98%weekly 98% left周额度还剩约 98%十三、Codex 常用命令进入 Codex 后可输入/model切换模型和推理强度。/status查看当前模型、权限、目录和 token 使用情况。/usage查看使用量。/usage daily /usage weekly /usage cumulative查看每日、每周、累计使用量。/statusline手动配置底部状态栏。/debug-config检查配置文件是否生效。/quit退出 Codex。十四、Codex 升级方式因为当前是通过curl-fsSLhttps://chatgpt.com/codex/install.sh|sh安装的所以升级也是重新执行这条命令curl-fsSLhttps://chatgpt.com/codex/install.sh|sh升级后检查whichcodex codex--version正常路径应仍然是/home/muxia/.local/bin/codex不建议使用npminstall-gopenai/codexlatest否则可能出现 npm 版和 standalone 版混用导致路径混乱。十五、创建升级快捷命令可以创建一个别名echoalias codex-upgradecurl -fsSL https://chatgpt.com/codex/install.sh | sh codex --version~/.bashrcsource~/.bashrc以后升级只需要codex-upgrade十六、检查 Codex 有没有更新查看本地版本codex--version启动 Codex 时如果有更新通常会提示Update available!也可以用 GitHub latest release 检查curl-sIhttps://github.com/openai/codex/releases/latest|grep-ilocation十七、建议的日常使用流程打开 Ubuntuwsl-d Ubuntu-24.04进入项目cd~/workspace/你的项目打开 VS Codecode.启动 Codexcodex重要修改前先提交 Gitgitadd.gitcommit-mbefore codex changes查看 Codex 改了什么gitdiff不满意可以回滚gitrestore.十八、最终理解Windows 负责VS Code、WPS、Word、浏览器、办公软件Ubuntu / WSL2 负责Codex、Git、Python、Node、Java、AI Agent、项目运行和文件生成最佳实践Windows 看文件 Ubuntu 跑命令 Codex 操作 WSL2 项目 正式文件先复制副本再处理