iterm2多端实时同步有三种方案:一是icloud自动同步,通过软链配置至icloud drive并设置自定义路径;二是git版本化同步,导出plist纳入仓库管理后跨设备拉取导入;三是符号链接+本地存储,统一导出至本地目录再用同步工具托管整个文件夹。
要让 iterm2 的环境设置在多台 mac 上实时同步,关键是把配置文件从系统沙盒里“移出来”,放到一个所有设备都能访问、且能自动或手动保持一致的位置。iterm2 本身不内置云同步,但 macos 生态提供了几种稳定可靠的路径。
iCloud 自动同步(苹果用户首选)
适合日常使用、不想碰命令行、设备都登录同一 Apple ID 的人。iTerm2 原生支持读取自定义偏好路径,配合 iCloud Drive 就能实现修改即同步。
- 确保 iCloud Drive 已开启,且“桌面与文稿文件夹”同步已启用(非必须,但建议)
- 在每台 Mac 上执行:
mkdir -p ~/Library/Mobile\ Documents/com~apple~CloudDocs/iTerm2ln -sf ~/Library/Preferences/com.googlecode.iterm2.plist ~/Library/Mobile\ Documents/com~apple~CloudDocs/iTerm2/ - 打开 iTerm2 → Preferences → General → Preferences,勾选 Load preferences from a custom folder,路径填:
~/Library/Mobile Documents/com~apple~CloudDocs/iTerm2 - 重启 iTerm2,改一个 Profile 名称,等 5–10 分钟,另一台设备打开 Profiles 页面就能看到更新
Git 版本化同步(开发者推荐)
适合需要回滚、审计、协作或长期维护配置的人。把配置当代码管,安全、可追溯、易复现。
- 在主设备创建仓库:
mkdir -p ~/git/configs/iterm2 && cd ~/git/configs/iterm2defaults export com.googlecode.iterm2 com.googlecode.iterm2.plistgit init && git add . && git commit -m "init" - 推送到 GitHub/GitLab 私有仓库
- 新设备上:
cd ~/git/configs/iterm2 && git pulldefaults import com.googlecode.iterm2 com.googlecode.iterm2.plist - 重启 iTerm2 即可生效
- 日常更新只需
git add && git commit && git push,其他设备git pull && defaults import && restart
符号链接 + 本地集中目录(兼顾隐私与可控)
不依赖 iCloud 或 Git,用本地文件夹作唯一源头,再靠 Dropbox / Syncthing / rsync 等工具同步该文件夹。
- 在主设备建统一目录:
mkdir -p ~/configs/iterm2 - 导出配置到该目录:
defaults export com.googlecode.iterm2 ~/configs/iterm2/com.googlecode.iterm2.plist - 在所有设备上建立软链指向这个文件:
rm ~/Library/Preferences/com.googlecode.iterm2.plistln -s ~/configs/iterm2/com.googlecode.iterm2.plist ~/Library/Preferences/ - 启动 iTerm2 后,进入 Preferences → General → Preferences,勾选 Load preferences from a custom folder,路径填:
~/configs/iterm2 - 同步工具只需托管
~/configs/iterm2整个文件夹即可
这三种方式都不需要修改 iTerm2 源码,也不依赖第三方插件。只要配置文件路径一致、权限正常、plist 格式未损坏,同步后就能立即反映在界面上。选哪一种,取决于你对自动性、版本控制和数据主权的优先级。











