Как установить chezmoi: init, add dotfiles и apply на новом компьютере
Dotfiles в Git-источнике chezmoi; новая машина — init и apply.
Новый ноутбук or a fresh OS install means copying ~/.zshrc, SSH config, and editor settings by hand. chezmoi keeps dotfile sources in Git: chezmoi add on the machine you use today, chezmoi init plus chezmoi apply on the next one. Материал: установка macOS/Linux, chezmoi init, add dotfiles, edit/diff, первый apply на новой машине для читателей hereink.
The query is how to install chezmoi manage dotfiles and apply on a new machine. You should finish with chezmoi installed, a initialized source tree, at least one config file under management, and a successful apply after cloning your source elsewhere.
Что решает chezmoi
Versioned dotfiles
Track ~/.gitconfig, shell rc, ~/.config/nvim, and friends in one Git repo instead of ad hoc backups. Changes diff cleanly and roll back across machines.
Templates and secrets
chezmoi supports templates (OS-specific paths) and pulling secrets from 1Password and similar—so you do not commit live tokens. Start with plain add, then move edits to chezmoi edit.
Upstream:
github.com/twpayne/chezmoi, docs atchezmoi.io. Runchezmoi --versionafter install.
Установка chezmoi
- 1macOS (Homebrew)
brew install chezmoi. Verify withwhich chezmoiandchezmoi --version. - 2Linux
Official installer:
sh -c "$(curl -fsLS get.chezmoi.io)" -- -b $HOME/.local/bin, then put$HOME/.local/binonPATH. Distro packages are listed on chezmoi.io. - 3First init
chezmoi initcreates the source tree under~/.local/share/chezmoi. If you already host dotfiles on GitHub:chezmoi init https://github.com/YOUR_USER/dotfiles.git.
Добавление файлов
Paths in the source are relative to home. To manage your current ~/.zshrc:
chezmoi add ~/.zshrc
chezmoi cd
git status
git commit -m "Add zshrc"
git pushchezmoi add copies into the source with permissions preserved. After that, change configs with chezmoi edit ~/.zshrc (edit source, then apply to home) so home and source do not drift.
Локальный apply и команды
chezmoi apply
chezmoi diff
chezmoi status
chezmoi updateRun chezmoi diff before chezmoi apply so you see what will overwrite live files.
Восстановление на новом ПК
- 1Install chezmoi
Same brew or get.chezmoi.io steps as above.
- 2Init your source
chezmoi init https://github.com/YOUR_USER/dotfiles.git. Private repos need SSH or HTTPS credentials already configured. - 3First apply
chezmoi apply -v. Dry-run first:chezmoi apply -nv. Drop-nonce the diff looks right. - 4Stay in sync
chezmoi updatepulls and applies; local changes go back viachezmoi re-addor edit, commit, and push.
vs rsync или Git в ~
| Approach | Multi-machine | Permissions / templates |
|---|---|---|
| Manual cp / rsync | Easy to miss files | You track it |
| Git in home only | Works; easy to leak secrets | No built-in templating |
| chezmoi | init + apply / update | add, templates, secret hooks |
- Подходит
- Several Mac/Linux machines, shared shell/editor/SSH setup, clear Git history for dotfiles.
- Не подходит
- Single machine, tiny config, never reinstall—plain backup may be enough.
Edited ~/.zshrc but chezmoi status shows drift?
You changed the live file. Run chezmoi re-add ~/.zshrc to capture into source, or chezmoi apply to reset home from source (destroys uncommitted home edits—diff first).
How is this different from GNU stow?
stow symlinks a package tree into home; chezmoi keeps a separate source and applies it, with templates and cross-OS support. Pick one workflow.
Windows?
chezmoi supports Windows with different paths and shells—see chezmoi.io. WSL users often manage Linux home separately from Windows dotfiles.
После настройки — схема на доске
Once terminal and editor settings match, service boundaries still belong on a shared canvas. See как создать пространство.