Cygwin 是在 Windows 上提供**類 Unix 環境**的開源工具集,包含:
setup-x86_64.exe (64位) 或 setup-x86.exe (32位)C:\cygwin64 (避免空格、中文路徑)mirrors.aliyun.com, mirrors.tuna.tsinghua.edu.cn)在「Select Packages」頁面,搜尋並勾選 (點擊 Skip → 版本號):
| 類別 | 套件名 | 用途 | |
|---|---|---|---|
| Devel | gcc-core, gcc-g++, gdb, make, cmake, binutils | C/C++ 編譯鏈 | |
| Devel | git, subversion, mercurial | 版本控制 | |
| Editors | vim, nano, emacs | 文本編輯器 | |
| Shells | bash, zsh, fish | Shell 環境 | |
| Utils | coreutils, findutils, diffutils, grep, sed, gawk | 核心工具 | |
| Libs | libncurses-devel, libreadline-devel, openssl-devel | 開發庫 | |
| Python | python3, python3-pip | Python 3 | |
| Perl | perl, perl-modules | Perl |
| 問題 | 解決方案 |
|---|---|
gcc: command not found | 未安裝 gcc-core 或 PATH 未生效,重開終端 |
| Windows 路徑含空格導致編譯失敗 | 避免空格路徑,或用引號包裹 |
fork() 失敗 / 記憶體不足 | 重啟電腦;關閉防毒軟體;增加 swap |
| 行尾符 ^M (CRLF) 導致腳本錯誤 | dos2unix script.sh 或 git config core.autocrlf input |
| 權限拒絕 | chmod +x script.sh;檢查 Windows 防毒軟體攔截 |
| 中文顯示亂碼 | 設置 LANG/LC_ALL;Terminal 字體選支援中文 (如 Microsoft YaHei) |
| 特性 | Cygwin | WSL2 | MSYS2 |
|---|---|---|---|
| 架構 | DLL 轉譯層 | 真實 Linux 核心 (VM) | MinGW + Bash |
| 效能 | 中 (轉譯開銷) | 高 (原生) | 高 (原生 Windows 二進制) |
| Linux 相容性 | 高 (POSIX 層) | 完美 | 中 (針對 Windows 原生) |
| Windows 互操作 | 原生 (同進程) | 需網路/9P 掛載 | 原生 |
| 圖形界面 | X Server (VcXsrv) | Wayland/X11 (WSLg) | 需額外配置 |
| 適用場景 | 舊專案移植、跨平台構建 | 現代 Linux 開發、Docker | Windows 原生 CLI 工具開發 |
Cygwin 是 Windows 上經典的類 Unix 環境,適合**舊代碼移植、跨平台構建腳本、輕量級開發**。現代新專案優先考慮 WSL2 (完整 Linux 體驗) 或 MSYS2 (原生 Windows 二進制)。掌握「套件選擇、PATH 管理、編碼設置、路徑映射」四大配置要點,能讓 Cygwin 穩定高效運行。