Tools / July 8, 2024 / 2 mins read / By Wagner Matos

How to setup GNU Stow with existing dotfiles

Dotfiles are configuration files for applications and shell environments, often prefixed with a dot (.), making them hidden by default. Managing these files across different systems can be challenging. GNU Stow helps by creating symbolic links from a central directory (usually a Git repository) to the appropriate locations in your home directory.

installing GNU Stow

To install GNU Stow, you can use your package manager. Here are the commands for different systems:

On macOS (using homebrew)

brew install stow

Debian based systems, e.g. Ubuntu

sudo apt-get update
sudo apt-get install stow

On Arch systems

sudo pacman -S stow

Creating Your Dotfiles Repository

First, create a directory to hold your dotfiles. This is typically a Git repository, allowing you to version control and sync across multiple machines

mkdir ~/dotfiles
cd ~/dotfiles
git init

Organizing Dotfiles for Stow

In the ~/dotfiles directory, create subdirectories for each application. For example:

mkdir -p ~/dotfiles/bash
mkdir -p ~/dotfiles/vim
mkdir -p ~/dotfiles/git

Move Existing Dotfiles to the Repository

Before moving your existing dotfiles, it’s essential to back them up. You can do this by copying them to a backup directory.

mkdir ~/dotfiles_backup
cp ~/.zshrc ~/.vimrc ~/.tmux.conf ~/dotfiles_backup/

Navigate to your ~/dotfiles directory and use Stow to create symlinks for your dotfiles. Stow will create symlinks in your home directory, pointing to the files in your ~/dotfiles repository.

cd ~/dotfiles
stow zsh
stow vim
stow tmux