GNU StowUnrelated Administrative I

Found at: colorfield.space:70/~jboverf/gnu_stow.txt

GNU Stow

Unrelated Administrative Note:

I don't want to go back and modify all the other
posts, but going forward this phlog will wrap
lines to 50 characters so they look good on mobile
(this is based on a Mastodon post by solderpunk
which asked people to test what widths worked
well on common mobile platforms).

Regularly Scheduled Programming:

Like many programmers who "exist" on lots of
different systems, I like to manage various
"dotfiles" (configuration files) using version
control (in my case, Git). I also tend to like
using the latest and greatest versions of open
source software, and as a result I install from
source files very often on a variety of
platforms. Also, since I have accounts on several
public access UNIX systems, I am used to
installing software on constrained accounts where
I can't install to system directories and often
don't want to bother admins for software that
may not be applicable to all users of the system.

I use GNU Stow [1] to help me manage both
dotfiles and source installations. GNU Stow is
essentially a symlink manager. The prescribed way
on the GNU Stow site is to manage source
installations where you *can* install to system
directories like /usr/local. So, you'd have a
folder like /usr/local/stow/foo for package foo
and /usr/local/stow/bar for package bar. When you
install from source, you set the PREFIX in the
configure or make step to /usr/local/stow/foo,
and you get /usr/local/stow/foo/[bin,share].
Now, you can go into /usr/local/stow and type
`stow foo`, which will take everything inside
that directory and symlink it one level up
(this too is configurable - you can have it put
the symlinks anywhere).

This does the right (safe) thing and doesn't
clobber anything. If /usr/local/bin already
exists (it probably does), then it will symlink
to the actual binaries inside of

You can probably see where I'm going here, but
this works in the same way for "local" installs.

Pick a directory under your $HOME that you want
source installs to live in. I'd recommend
$HOME/.local. Under that directory, make a "stow"
directory, and then everything from the above
applies cleanly. You will need to add
$HOME/.local/bin to your $PATH and
$HOME/.local/share/man to your $MANPATH among
other potential environment variables depending
on what you're installing.

Now, when you compile a new version, you can move
the old $HOME/.local/stow/foo directory to
foo-version and make a new foo directory to send
the compiled files to. Now your symlinks stay
the same but you installed a new version. Also,
the old version is still around if you need to
roll back quickly.

If you want to delete a package, go to your stow
directory and run `stow -D foo` and the symlinks
are gone! No more hunting around for stray files
in random directories.


Dotfiles can be managed similarly, check out
this [1] excellent blog post about it. The TL;DR
is: have a folder called "dotfiles" in your $HOME
that contains folders for all the programs whose
config files you want to track. For me, that
involves config files like ".bashrc" and
the things in ".vim", so I have folders under
$HOME/dotfiles called "vim" and "bash". Move
your actual dotfiles from your $HOME dir to the
right folder under $HOME/dotfiles (.bashrc goes
to $HOME/dotfiles/bash for example). Then, in
$HOME/dotfiles, run `stow bash` and `stow vim`.

Now, all your configuration files are in one
place, and they can be source controlled easily.


[1] https://www.gnu.org/software/stow/
[2] http://brandon.invergo.net/news/2012-05-26-using-gnu-stow-to-manage-your-dotfiles.html