建立一個 完整的 macOS 終端環境(Terminal Dev Environment),使用 iTerm2 為核心,搭配強化的 shell、工具與主題,可以大幅提升你在 macOS 上的開發效率與操作體驗。
以下是 一步一步的實戰流程,讓你打造出專業且美觀的終端環境。
🎯 目標:打造一個具有以下特性的終端環境
- ✅ 使用 iTerm2 做為高效終端模擬器
- ✅ 裝上美觀的 Powerlevel10k Zsh 主題
- ✅ 整合 oh-my-zsh、Homebrew、常用 CLI 工具
- ✅ 支援 Git、Node.js、Python、Docker 等開發工具
- ✅ 擁有自訂配色方案(如 Dracula)與分割視窗能力
🛠️ 一、基礎工具安裝
1. 安裝 Homebrew(macOS 的套件管理工具)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
驗證:
brew doctor
2. 安裝 iTerm2
brew install --cask iterm2
✅ 開啟 iTerm2,之後都會以它為你的主終端程式。
🧑💻 二、Zsh + Oh My Zsh + Powerlevel10k 主題
macOS 預設使用 Zsh,但我們還要讓它強大與美觀。
1. 安裝 Oh My Zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
2. 安裝 Powerlevel10k 主題
brew install romkatv/powerlevel10k/powerlevel10k
在 .zshrc 中啟用:
echo 'source $(brew --prefix)/opt/powerlevel10k/powerlevel10k.zsh-theme' >> ~/.zshrc
首次開啟時會引導設定字體與樣式(建議選:Lean 風格)
🎨 三、安裝 Nerd 字體(for Powerlevel10k)
brew tap homebrew/cask-fonts
brew install --cask font-meslo-lg-nerd-font
在 iTerm2 設定字體:
- Preferences → Profiles → Text → Font → 選擇
MesloLGS NF
🔧 四、安裝常用 CLI 工具
brew install git wget curl tree htop jq fzf zsh-autosuggestions zsh-syntax-highlighting
然後修改 ~/.zshrc:
# 自動建議
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# 語法高亮
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
重載設定:
source ~/.zshrc
💻 五、安裝常用開發工具
brew install node python go rust
brew install --cask docker visual-studio-code postman
可選:
brew install nvm
brew install pyenv
🖥️ 六、iTerm2 外觀設定(提升體驗)
1. 匯入配色方案(如 Dracula)
git clone https://github.com/mbadolato/iTerm2-Color-Schemes.git
cd iTerm2-Color-Schemes
open schemes
然後在 iTerm2 → Preferences → Profiles → Colors → Color Presets → Import → 選擇 .itermcolors 檔案 → 套用
2. 設定透明背景 & 無邊框字體
- Preferences → Profiles → Window → Transparency: 10~20%
- Profiles → Text → Anti-aliased ✔︎,Use ligatures ✔︎
🧱 七、常用目錄結構建立
mkdir -p ~/Projects/{personal,work,learning,scripts}
🧪 八、選配功能(進階)
tmux(多工會話工具):brew install tmuxzoxide(cd 增強工具):brew install zoxidebat(美化版 cat):brew install batglow(Markdown 閱讀器):brew install glowgh(GitHub CLI):brew install gh
💾 九、備份與還原建議
匯出 iTerm2 設定:
- Preferences → General →
Load preferences from a custom folder - 存入:
~/dotfiles/iterm2/
匯出 zsh 設定:
cp ~/.zshrc ~/dotfiles/zshrc
✅ 十、環境完成後的預期畫面
你會擁有一個:
- 使用
iTerm2 + Powerlevel10k的美觀終端 - 支援 Git、Node、Python、Docker 的開發環境
- 一套能跨設備備份與還原的設定系統
- 高效率操作體驗(快捷鍵 + 分割窗格)