Package management for your home directory with stow

I sometimes run into the problem that I work on a computer (via ssh) which does not have all the tools and libraries installed that I want to use. In the past I went on and compiled all I needed manually and installed them into ~/opt.

Problem: you don’t have any kind of package management for the stuff you installed into ~/opt.

Solution: GNU stow

GNU Stow is a symlink farm manager which takes distinct packages of software and/or data located in separate directories on the filesystem, and makes them appear to be installed in the same place.

With stow you install each piece of software into a different directory and you use stow to create symlinks.

So here is what you have to do:

  1. Create ~/opt folder with all the usual subfolder (bin, etc, include, lib, share, …)
  2. Create ~/opt/stow folder for your package
  3. Get GNU stow (obviously) and put the stow script into ~/opt/bin
  4. If not done already, put ~/opt/bin to your path
  5. Create a .stowrc with the following content
  6. Install something (e.g. tmux):

    $ tar xzf tmux-1.5.tar.gz
    $ cd tmux-1.5
    $ ./configure --prefix=$HOME/opt/stow/tmux-1.5
    $ make install

Now you can use stow tmux-1.5 to activate the installed ‘package’. This will create symlinks in ~/opt which point to $HOME/opt/stow/tmux-1.5.

One advantage over installing everything directly into ~/opt is that uninstalling is much easier (e.g. stow -D tmux-1.5). Another advantage is that you can have multiple versions of a library installed and switch between them. I use this for example to switch between different BLAS implementations.

BTW, if you are running Debian and do not want to compile things or if you just need some header files for existing libraries you can also install DEB packages using something like this script:

debname=`basename $1 .deb`
mkdir ${targetdir}
dpkg -x  ${debfile} ${targetdir}
mv ${targetdir}/usr/* ${targetdir}/
rm -rf ${targetdir}/usr
stow ${debname}

Additional infos



Tags: ,

1 comment

  1. To completely follow the tradition, I think you should use ~/local as the place to put your symlinks, because ~/opt is not supposed to contain the usual unix tree (bin, lib …).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.