I install a lot of programs form source on my machine, and I have long been worried at a low level about how this will clutter the /usr/local/... directories on my system with many files. This is a problem that package managers are supposed to solve, but if you build from source, you don’t get a nice package. Once I have built and installed a program, what will enable me to remove all the files relating to it again? Sure, maybe I can use make uninstall, but only if the makefile has the uninstallation rules. That’s not much of a consolation.
What is Stow
I recently learned of the existence of GNU Stow (and it’s cousin, xStow), which are tools to keep your system clean, even when building from source. They are more flexible and straightforward in my opinion than CheckInstall, which creates a package to install using the normal package manager, but doesn’t work all the time.
You install your program to a separate folder hierarchy, which is used only by that program. Stow then creates symlinks from the “path” directory (the place you normally install to, often /usr/local) to the files in the program’s special directory. The symlinks relating to a certain program can then be easily identified by looking at which directory they point to, and stow can then remove them automatically at will. Thus, while your /usr/local/... folder will have the same number of files (actually symlinks to files), organised in the same way they used to be, every one of them will be bound to a program via the symlink target.
The diagram below shows the structure of a stow hierarchy based around /usr/local (showing only bin, lib and share). The files belonging two applications, “app1″ and “app2″ are identified by which application directory they point to, indicated by the colour of the arrow.

Stow workflow
Consider the “usual” installation procedure:
./configure
make
make install
When you build your program, you use the prefix options for ./configure and make install commands, which will install the program to a separate directory, keeping all the files associated with that program in their own folder hierarchy. Not all programs need the prefix in both steps, but it won’t hurt to provide it.
./configure --prefix=/usr/local/stow/appname
make
make install prefix=/usr/local/stow/appname
Now, change to the directory specified, and you will see that you have the familiar folders such as bin, lib, include, share etc. Which you have depends on the program. Of course, they are not in the /usr/local directory, so the program can’t be run, as the current directory isn’t on your PATH. The program is installed, but is not findable.
To create the symlinks from /usr/local/bin and friends, go to the /usr/local/stow directory, and run the following command:
That is it, your program is now installed into /usr/local, but the files are safely filed away in their own folder. To remove the program again, just go to the stow directory again and enter:
This will scan for the symlinks targeting the appname directory, and delete them. Notice that access to the original source and makefiles is not needed. It will not delete the directory itself, so you can “uninstall” temporarily without removing the files, so no rebuild is required.
On directories and environment variables
You do not need to use /usr/local for your installed programs. Stow will work just as happily with a directory in your home directory such as ~/opt. In that case the Stow directory will be ~/opt/stow, and you’d install to ~/opt/stow/appname. Of course, whichever directory you choose needs to be on your PATH environment variable for the programs to work.
A useful tip is to create a STOW environment variable, so that you can run the following commands:
./configure --prefix=$STOW/appname
make
make install prefix=$STOW/appname
cd $STOW
stow appname
Uninstallation is as simple as:
I find this helps visualise what is going on. You can add this command with the following line in your .bash_profile script:
export STOW=/usr/local/stow
Installing Stow using Stow
If you have a system without a package manager, and you build from source, then you can use the binary you just build to stow Stow, so to speak. You perform the same build steps as before, but in the last command, reach down into the Stow directory and use the binary directly. It hasn’t been linked into a directory on the PATH, so you can’t just call stow.
./configure --prefix=$STOW/stow
make
make install prefix=$STOW/stow
cd $STOW
./stow/bin/stow stow
About Stow and xStow
GNU Stow is a Perl script; xStow is a C++ program, which means you can install it using only a C++ compiler, and you don’t need a Perl installation to begin stowing things (like Perl). Thus xStow may be easier to bootstrap than Stow on a bare system.
xStow also supports various other operations, some of which are not compatible with stow. Thus if you use that operation with xStow, you cannot then change back to Stow. if you don’t do those operations, the two are equivalent.