Package management tools like apt-get make it very easy to install and remove software. The package manager takes care of downloading the package together with its dependencies if, of course, someone has taken the time to create a package and made it available to you. In some cases, you don’t want to interfere with your local package management, however. With a bit of bad luck, third party packages can mess up your package system or cause conflicts when upgrading your distribution.
Because of this, people often install source packages to
/usr/local without bothering to create deb or rpm packages. The problem with this approach is that it leads to a lot of clutter in
/usr/local and it makes uninstalling software pretty difficult. Using the stow tool, you can easily install software from source and uninstall it later. Stow doesn’t even need a package database or configuration files for this.
The idea of stow is to install each software package into a directory structure on its own and use symlinks to make it available to the rest of the system. Suppose you want to install a nice little software package (let’s call it
yourpackage-0.1) from source. You would then install it in
/usr/local/stow/yourpackage-0.1, where it has its own directory structure with
include and other directories. Stow would then create symlinks, so that
/usr/local/bin/foo would be a symlink to
If you’re using stow for the first time, you have to create the
/usr/local/stow directory. It doesn’t have to be owned by root; on my system it belongs to the src user, which I use to install software.
Let’s install two software packages from source to see how it works. The first example is libdiscid, a library written in C which has autoconf support:
$ tar xvzf libdiscid-0.1.tar.gz $ cd libdiscid-0.1 $ ./configure --prefix=/usr/local/stow/libdiscid-0.1 $ make $ make install # cd /usr/local/stow && stow libdiscid-0.1 # ldconfig
--prefix argument which tells
configure where to install the package. The first five commands can be executed by the user owning
/usr/local/stow. Only the creation of symlinks done by the stow tool requires root privileges. The
ldconfig call is required for libraries to tell the dynamic linker about the new library.
Python packages work much the same way. We’ll use python-musicbrainz2 as a demo:
$ tar xvzf python-musicbrainz2-0.4.0.tar.gz $ ./setup.py install \ --prefix=/usr/local/stow/python-musicbrainz2-0.4.0 \ --install-layout=deb # cd /usr/local/stow && stow python-musicbrainz2-0.4.0
--install-layout=deb parameter is only relevant for Debian-based systems.
Uninstalling a software package works using the following command:
# cd /usr/local/stow && stow -D python-musicbrainz2-0.4.0
This only removes the symlinks but not the package itself. To get rid of it altogether, you have to remove the
python-musicbrainz2 directory manually.