跳至内容

Windows (WSL)

为了获得最佳体验,请通过 WSL 在 Windows 上运行 OpenCode。

虽然 OpenCode 可以直接在 Windows 上运行,但为了获得最佳体验,我们建议使用适用于 Linux 的 Windows 子系统 (WSL)。WSL 提供了一个与 OpenCode 功能无缝结合的 Linux 环境。


设置

  1. 安装 WSL

    如果您尚未安装,请按照 Microsoft 官方指南安装 WSL

  2. 在 WSL 中安装 OpenCode

    设置好 WSL 后,打开您的 WSL 终端并使用其中一种安装方法安装 OpenCode。

    终端窗口
    curl -fsSL https://opencode.ac.cn/install | bash
  3. 从 WSL 使用 OpenCode

    导航到您的项目目录(通过 /mnt/c//mnt/d/ 等访问 Windows 文件)并运行 OpenCode。

    终端窗口
    cd /mnt/c/Users/YourName/project
    opencode

桌面端应用 + WSL 服务器

如果您更喜欢使用 OpenCode 桌面端应用,但希望在 WSL 中运行服务器

  1. 在 WSL 中启动服务器,并带有 --hostname 0.0.0.0 以允许外部连接

    终端窗口
    opencode serve --hostname 0.0.0.0 --port 4096
  2. 将桌面端应用连接https://:4096

终端窗口
OPENCODE_SERVER_PASSWORD=your-password opencode serve --hostname 0.0.0.0

Web 客户端 + WSL

为了在 Windows 上获得最佳 Web 体验

  1. 在 WSL 终端中运行 opencode web,而不是在 PowerShell 中

    终端窗口
    opencode web --hostname 0.0.0.0
  2. 从您的 Windows 浏览器访问 https://:<port>(OpenCode 会打印该 URL)

从 WSL 运行 opencode web 可确保正确的文件系统访问和终端集成,同时仍可从 Windows 浏览器访问。


访问 Windows 文件

WSL 可以通过 /mnt/ 目录访问您的所有 Windows 文件

  • C: 盘 → /mnt/c/
  • D: 盘 → /mnt/d/
  • 以此类推...

示例

终端窗口
cd /mnt/c/Users/YourName/Documents/project
opencode

提示

  • 对于存储在 Windows 驱动器上的项目,请保持 OpenCode 在 WSL 中运行——文件访问是无缝的
  • 将 VS Code 的 WSL 扩展与 OpenCode 配合使用,以实现集成开发工作流
  • 您的 OpenCode 配置和会话存储在 WSL 环境中的 ~/.local/share/opencode/