07 minute read

GNU stow is amazing

I was tired of redoing settings after installs and turned my config files into a git-backed repo and let GNU Stow do its magic.

Now that I’ve been using Linux for a few weeks, I quickly realised I would need some way to take care of my precious configuration. The amazing thing about Linux is that everything is a file. I love that—but how is that related to stow?

My background

I promised to myself I wouldn’t turn this post into an essay, so let’s just swiftly glide over this one as quickly as we can, shall we?

I used macOS for the last 20 years or so—that’s a long time… especially in software world!

Every time I needed to do a fresh install I wondered if there was no other way of doing it. I mean, going over every single app I needed to install, install it, open the settings for that app and configure it how I like it.

At some point I stopped being an ice-age man and started doing this with Homebrew. Instead of going to every single website and look for the “download” button, I could just search for the app from a list and install it. Far easier. And quicker too!

But that’s just the installation part of the process. The most tedious one is by far the configuration of each individual app. Especially considering that there’s no standard for it. And that… I had no clue how to solve.

Enter dotfiles

Since everything is a file in Linux—and truthfully told, there are some apps in macOS that follow this practice too—it became obvious to me that I could just backup those files and reuse them later on if/when I needed to do a clean install.

Configuration files are usually referred to as “dotfiles”. These are files that begin with a dot. For instance, .zshrc is the configuration file for the ZSH shell. Just like .tmux.conf is the configuration file for TMUX.

These files live in your home folder and by default, both macOS and Linux hide files that begin with a dot. That’s why you don’t see them in Finder, until you enable it.

So… stow?

Right! You could be wondering, if I already have the dotfiles, I could just backup those, right?
Indeed, I could!

But then what? Are you expecting me to update my backups whenever I change a configuration file?

You know that’s never going to happen. Which means I would end up with an old configuration file in the next fresh install.
Better than nothing! But still not ideal.

If you come from Windows, you might be familiar with the “alias” concept. That’s when a file points to another file. It’s just a pointer. See where this is going already?

In Linux and macOS this concept is called symbolic link—or symlink for short. Same idea. For instance, you could have a configuration file that is just a pointer to the actual configuration file.

This is the key! Can you see the magic already?

Let me put this crystal clear.
You can have your own git repo full of configuration files, stored anywhere you like, mimicking the same structure you would have in your home directory, and rely on a tool like GNU stow to manage the symlinks for you.

So I have my own pmpinto/dotfiles repo where I store a .zshrc file as well as a .tmux.conf file along with plenty of other files inside a .config/ folder. They are all configuration files. They are just in different directories.

My job is to make sure those files are up to date, just like any other repo.
I have this repo cloned into my home folder.

The benefits of stow come in place when you remove—or backup, I should say—your current config files and create symlinks for your repo. Basically, my /home/pmpinto/.zshrc file is now just a pointer to the one in my dotfiles repo /home/pmpinto/.zshrc -> /home/pmpinto/dotfiles/.zshrc.

This still means I can just edit ~/.zshrc as I normally would. It just points to the one in my dotfiles repo now. And since that’s a git repo, I can not only commit and push to keep remote up to date, but I could also look back and reuse an older version if something goes wrong.

But how do you actually use it?

To use stow you just need to run a single command.

After installing it however you may prefer, and making sure your dotfiles repo is already cloned at your home directory, the only thing you need is to run stow . from your dotfiles repo directory. That’s it!

Stow will create symlinks for every file in your dotfiles repo and place them in their respective directories. The answer is: conventions—as it usually is!

Your dotfiles repo needs to have the exact same structure your config files do. This means that if you have a config that lives in ~/.config/hypr/hyprland.conf you need to have it in ~/dotfiles/.config/hypr/hyprland.conf. This way, stow will know where to place the symlink to your files.

Final thoughts

This is nothing new! That’s what’s the most fascinating thing to me. GNU stow has been around for something like 30 years, if I´m not mistaken. Even when I started using macOS, it was already around for 10 years.

For a very long time I was stuck in this visual side of software. I’m a visual guy, let’s face it! But when you limit yourself not only to software that has a visual interface but also to visual interfaces you find will provide a great experience, you miss out on great software.

There are plenty of great command line tools I’ve become aware of over the years, but I feel like this has accelerated greatly when I started my Linux journey most recently.

Command line tools may feel frightening at first. But the truth is that it provides way more control than any GUI. Besides, CLI tools can also be exciting! Tools like fzf—that allow for an interactive way of fuzzy finding something in a list—or lazygit—an interactive CLI tool to interact with a git repo—make dealing with a terminal window a joy!

For instance, configuring my terminal app in a way that it reuses my command history piped through fzf, makes it extremely easy for me to find commands that I would never remember again without an extensive search session.

I’m honestly much more excited for TUIs—textual user interfaces—like these than I ever was for Apple’s Liquid Glass. This has to mean something!

Photo of Pedro