看到一直在转,说明命令卡住了。这通常是因为**网络请求超时**——npm 在尝试连接 registry.npmjs.org,但国内访问这个官方源速度极慢或者被阻断。

我们换个思路,**用国内镜像源加速下载**,同时配合超时设置来解决。

---

### 🚀 方案一:使用淘宝镜像源(最快)

直接换成国内的 npm 镜像源,下载速度会快很多:

```powershell
# 设置淘宝镜像源
npm config set registry https://registry.npmmirror.com

# 然后重新安装(不指定 registry 参数,用刚才设置的源)
$v = npm view @openai/codex version
npm install -g "@openai/codex@$v" "@openai/codex-win32-x64@npm:@openai/codex@$v-win32-x64"
```

如果还是卡住,可以加上超时和并发限制:

```powershell
npm install -g "@openai/codex@$v" "@openai/codex-win32-x64@npm:@openai/codex@$v-win32-x64" --timeout=60000 --maxsockets=1
```

---

### 🔄 方案二:直接下载压缩包安装(绕过 npm 网络)

如果 npm 命令始终转圈,可以手动下载压缩包解压安装:

1. **找到具体的包名和下载地址**:
   先确定你要安装的版本号,比如 `0.119.0`,然后去淘宝镜像站手动下载。

2. **浏览器直接下载**:
   打开淘宝镜像站的文件列表:
   - 主包:`https://registry.npmmirror.com/@openai/codex/download/@openai/codex-0.119.0.tgz`
   - 或者直接下载完整的 Windows 版 tarball:`https://registry.npmmirror.com/@openai/codex-win32-x64/download/@openai/codex-0.119.0-win32-x64.tgz`

   > **注意**:把 `0.119.0` 换成你的目标版本。

3. **手动解压到 npm 全局目录**:
   下载后解压,把里面的文件复制到 npm 的全局 node_modules 目录下(通常是 `C:\Users\你的用户名\AppData\Roaming\npm\node_modules\@openai\codex\`),然后确保 `codex.exe` 或 `codex.cmd` 在系统 PATH 中。

---

### 📦 方案三:使用 cnpm(国内专用 npm 客户端)

`cnpm` 是淘宝团队开发的 npm 国内加速版,对网络问题处理得更好:

```powershell
# 先全局安装 cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com

# 然后用 cnpm 安装 codex
$v = cnpm view @openai/codex version
cnpm install -g "@openai/codex@$v" "@openai/codex-win32-x64@npm:@openai/codex@$v-win32-x64"
```

---

### 💡 方案四:检查网络环境

如果上面都不行,请检查以下几点:

1. **关闭 VPN/代理软件**:有些 VPN 会影响 npm 的连接,临时关掉再试。
2. **检查 npm 代理设置**:
   ```powershell
   npm config get proxy
   npm config get https-proxy
   ```
   如果有输出且不对,清除代理:
   ```powershell
   npm config delete proxy
   npm config delete https-proxy
   ```
3. **换成手机热点**:有时公司网络有限制,换个网络环境可能就通了。

---

### 🏆 最终兜底:用 WSL 2(Linux 环境)

在 WSL 2 里使用 **Ubuntu 镜像源**下载,基本不会有网络问题,而且安装命令更简单:

```bash
# 在 WSL 2 的 Ubuntu 终端中执行
sudo apt update
sudo apt install nodejs npm  # 或使用 nvm 安装最新版 node
npm install -g @openai/codex --registry=https://registry.npmmirror.com
```

---

你可以先试**方案一(淘宝镜像源)**,这个成功率最高。如果还是卡在转圈,告诉我具体卡在哪一步(是 `npm view` 卡住,还是 `npm install` 卡住),我再帮你针对性解决。

更多推荐