Files
tf_code/packages/web/src/content/docs/zh-tw/windows-wsl.mdx
2026-02-10 07:11:19 -06:00

114 lines
3.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Windows (WSL)
description: 在 Windows 透過 WSL 使用 opencode。
---
import { Steps } from "@astrojs/starlight/components"
雖然 opencode 可以直接在 Windows 上執行,但為了獲得最佳體驗,我們建議使用 [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install)。WSL 提供了可與 opencode 功能順暢配合的 Linux 環境。
:::tip[為什麼要用 WSL]
WSL 提供更好的檔案系統效能、完整的terminal支援以及與 opencode 依賴之開發工具的相容性。
:::
---
## 設定
<Steps>
1. **安裝 WSL**
如果你尚未安裝,請依照 Microsoft 官方指南[安裝 WSL](https://learn.microsoft.com/en-us/windows/wsl/install)。
2. **在 WSL 中安裝 opencode**
完成 WSL 設定後,打開 WSL terminal並使用其中一種[安裝方式](/docs/)安裝 opencode。
```bash
curl -fsSL https://opencode.ai/install | bash
```
3. **從 WSL 使用 opencode**
移動到你的專案目錄(可透過 `/mnt/c/`、`/mnt/d/` 等路徑存取 Windows 檔案),然後執行 opencode。
```bash
cd /mnt/c/Users/YourName/project
opencode
```
</Steps>
---
## 桌面應用程式 + WSL 伺服器
如果你偏好使用 opencode 桌面應用程式,但希望在 WSL 內執行伺服器:
1. **在 WSL 中啟動伺服器**,並使用 `--hostname 0.0.0.0` 允許外部連線:
```bash
opencode serve --hostname 0.0.0.0 --port 4096
```
2. **將桌面應用程式連線到** `http://localhost:4096`
:::note
若你的環境中 `localhost` 無法使用,請改用 WSL 的 IP 位址連線(在 WSL 執行:`hostname -I`),並使用 `http://<wsl-ip>:4096`。
:::
:::caution
使用 `--hostname 0.0.0.0` 時,請設定 `OPENCODE_SERVER_PASSWORD` 來保護伺服器。
```bash
OPENCODE_SERVER_PASSWORD=your-password opencode serve --hostname 0.0.0.0
```
:::
---
## Web 用戶端 + WSL
在 Windows 上取得最佳 Web 體驗:
1. **請在 WSL terminal執行 `opencode web`**,而不是在 PowerShell 執行:
```bash
opencode web --hostname 0.0.0.0
```
2. **在 Windows 瀏覽器中開啟** `http://localhost:<port>`opencode 會輸出該 URL
從 WSL 執行 `opencode web` 可確保正確的檔案系統存取與terminal整合同時仍可由 Windows 瀏覽器使用。
---
## 存取 Windows 檔案
WSL 可透過 `/mnt/` 目錄存取你所有的 Windows 檔案:
- `C:` drive → `/mnt/c/`
- `D:` drive → `/mnt/d/`
- 其他磁碟機也相同
範例:
```bash
cd /mnt/c/Users/YourName/Documents/project
opencode
```
:::tip
為了更流暢的使用體驗,建議將你的儲存庫 clone 或複製到 WSL 檔案系統(例如 `~/code/`)中,再從那裡執行 opencode。
:::
---
## 提示
- 即使專案存放在 Windows 磁碟機上,也建議在 WSL 中執行 opencode檔案存取會更順暢
- 可將 opencode 與 VS Code 的 [WSL 擴充套件](https://code.visualstudio.com/docs/remote/wsl)搭配使用,建立整合式開發流程
- opencode 的設定與工作階段會儲存在 WSL 環境中的 `~/.local/share/opencode/`