setupterminalhow tomacos
Learn how to organize and manage your dotfiles easily with GNU Stow. This simple guide will help you store, structure, and sync your configurations more efficiently
February 27, 2025
Setting up a personal computer has never been easy for me. Installing and configuring the apps sometimes becomes a tedious task, especially when I get a new computer since I need to re-install and re-configure everything from scratch.
My solution for this is by wrote an article about it. So, in case I need to replace my computer, I can reproduce my previous computer environment easier just by reading the article.
Following the guideline from that article is really helpful, but not for my Dotfiles.
Dotfiles often contains a lot of configuration files and I don’t want to manually copy paste them everytime I replace my computer.
In this article, I want to share how I eventually manage my Dotfiles, so it can be reproducible easily on other computers.
What’s challenging about Dotfiles is that they are often scattered across various locations, depending on the application. For instance:
.bashrc, .zshrc resides in the home directory~/.config/nvim/~/.ssh/Imagine if all of your Dotfiles are living in a single directory, so you can use Git to track every changes and then push them to a remote hosting like Github. Then you can just pull them on any computer you want. I’d pleased if that’s possible.
After digging the solution on the Internet, I found out that we can manage our Dotfiles easily using GNU Stow. This software enable us to manage every Dotfiles in a single directory ✨
To install GNU Stow, I prefer to use Homebrew because it’s really easy to use. Just run the command below:
brew install stow.dotfiles directoryFirstly, you need a directory to store all of your Dotfiles. For this case, I like to put them in the ~/.dotfiles directory, since the name is self-descriptive: “it contains my Dotfiles”.
Create yours if you haven’t:
mkdir ~/.dotfilesLet’s say you want to backup your Zsh config file, you’ll need to create a directory named zsh inside the ~/.dotfiles:
mkdir ~/.dotfiles/zshthen, move your ~/.zshrc file to that directory:
mv ~/.zshrc ~/.dotfiles/zsh/After you moved your .zshrc to the ~/.dotfiles/zsh/ directory, your Zsh shell now won’t be able to find the configuration file since Zsh expect the users to have a configuration named .zshrc in the Home directory. This is where Stow shines ✨
To make your zsh configuration file available to the Home directory again, make sure you’re inside the .dotfiles directory:
cd ~/.dotfilesAnd then run the command below:
stow zshA “package” in Stow is just a directory inside the ~/.dotfiles. So, your zsh directory is the package name. You can also name it everything you want.
When you run the stow xxx command, GNU Stow creates symbolic links (symlinks) from the files in the specified package directory (e.g., ~/.dotfiles/zsh) to their corresponding locations in the home directory.
This means that the actual files remain in the ~/.dotfiles directory, but they appear as if they are in the home directory. This is similar to a Windows shortcut.
.dotfiles directoryLet’s say you also want to store your Tmux, Neovim, and SSH configurations in the ~/.dotfiles directory. In this case, you just need to make sure each of them is moved to its corresponding package directory.
Example structure:
~/.dotfiles/├── nvim/│ └── .config/│ └── nvim/│ └── init.vim├── ssh/│ └── .ssh/│ ├── config│ └── id_rsa├── tmux/│ └── .tmux.conf└── zsh/ └── .zshrcWith the above directory structure, you need to run the stow command for each of them:
stow nvim ssh tmux zshor run for all packages
stow */The symlinks then will be created for each of them to the Home directory.
In case you want to delete the symlinks, just put the -D option when running the Stow:
stow -D packageNameOr run for all packages
stow -D */With every Dotfiles inside a directory, now it’s possible to track every changes you do to your Dotfiles with Git.
git initgit add .git commit -m "initial commit"With GNU Stow, it’s now possible for me to move to other computers and pull all of my configuration files just by cloning the .dotfiles from the Git remote and then running the stow */ command for all of my packages.
By organizing your Dotfiles with GNU Stow, you can save time and ensure consistency across different environments. This approach not only simplifies the setup process but also makes it easier to manage and update your configurations.
Happy dotfiling!
Comments