步驟 1:安裝 WSL 2 和 Ubuntu
1. 以管理員身份打開 CMD
wsl --install -d Ubuntu
此命令會自動安裝 WSL 2 和 Ubuntu 發行版。
安裝完成后重啟系統。
- 初始化 Ubuntu
在開始菜單中打開 Ubuntu,設置用戶名和密碼。
步驟 2:在 WSL 的 Ubuntu 中配置環境
- 更新軟件包列表
sudo apt update && sudo apt upgrade -y
- 安裝必要工具
sudo apt install curl git zsh -y
步驟 3:通過 Gitee 鏡像安裝 Oh My Zsh
3.1替換 GitHub 源為 Gitee 鏡像
- 手動下載安裝腳本
curl -fsSL -o install-ohmyzsh.sh https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
- 修改腳本中的倉庫源
sed -i 's/https:\/\/github.com\/ohmyzsh\/ohmyzsh.git/https:\/\/gitee.com\/mirrors\/oh-my-zsh.git/g' install-ohmyzsh.sh
- 執行安裝腳本
sh install-ohmyzsh.sh
- 設置 Zsh 為默認 Shell
chsh -s $(which zsh)
步驟 4:配置插件和主題(Gitee 源)
- 安裝語法高亮插件
git clone https://gitee.com/mirrors/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
- 安裝自動補全插件
git clone https://gitee.com/mirrors/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
- 啟用插件和主題
編輯 ~/.zshrc:
nano ~/.zshrc
- 修改主題(例如 agnoster):
ZSH_THEME="agnoster"
- 添加插件:
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
- 保存后運行:
source ~/.zshrc
步驟 5:解決字體顯示問題
- 安裝 Powerline 字體
- 下載 MesloLGS NF 字體 并安裝。
- 在 Windows Terminal 設置 → Ubuntu 配置文件 → 外觀 → 字體,選擇 MesloLGS NF
2.解決圖標亂碼 - 如果仍顯示亂碼,重啟終端或運行:
exec zsh
驗證安裝
- 檢查 Oh My Zsh 版本
omz version
- 測試功能
- 輸入錯誤命令時顯示紅色高亮。
- 輸入命令前綴時顯示灰色自動補全建議。
常見問題解決
- 安裝腳本報錯
- 手動下載腳本后檢查網絡權限:
chmod +x install-ohmyzsh.sh
- 插件未生效
- 確保插件路徑正確,例如:
ls ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
- WSL 訪問 Windows 文件
- 通過 /mnt/c 訪問 C 盤文件。
總結
-
核心邏輯:通過 WSL 運行 Linux 環境,全程使用 Gitee 鏡像源替代 GitHub。
-
關鍵命令:手動替換腳本中的倉庫地址,避免依賴 GitHub。
-
兼容性保障:在 WSL 的 Ubuntu 中執行 Linux 原生命令,繞開 Windows 的 curl 參數限制。