Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Using GNU stow to manage manually compiled software

profile picture
Author
Richard
Published
2019-09-06
Time to read
4 minutes reading time

Introduction

You may often want to compile and install software manually on Linux if it's not available through your distribution's package manager or the version available is too old. The common practice is to simply install them to /usr/local, however this can get messy if you try to uninstall a program that doesn't support make uninstall or two programs use conflicting filenames without you noticing.

In this tutorial, I'll explain how to use GNU stow to manage such locally installed software. You install software to /usr/local/stow and it takes care of creating symlinks to /usr/local and warning you of name clashes.

Step 1 - Install prerequisites

You should have GNU stow and the essential build tools installed. On Debian and Ubuntu, you can do it like this:

$ sudo apt install stow build-essential

(You may also need to install other packages such as cmake if needed for a program you're trying to install.)

Then set up an alias so you can call stow from any directory:

$ echo "alias stow='sudo STOW_DIR=/usr/local/stow /usr/bin/stow'" >> ~/.bashrc
$ source ~/.bashrc

(If you're using another shell, change ~/.bashrc to your shell's initialization file.)

Step 2 - Install the desired software

Let's assume you want to install a program called lipsum. Most of the installation steps will be the same as usual, but you will have to set the installation prefix to /usr/local/stow/lipsum.

I'll explain how to change the installation prefix with the two most commonly used build systems below.

Option 1 - Autoconf

$ ./configure --prefix=/usr/local/stow/lipsum
$ make
$ sudo make install

If there is no ./configure file, first run ./autogen.sh if it exists.

If there's only a plain Makefile, you may be able to do make PREFIX=/usr/local/stow/lipsum, or edit the Makefile and change /usr/local to /usr/local/stow/lipsum.

Option 2 - CMake

$ mkdir build && cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/stow/lipsum
$ make
$ sudo make install

Step 3 - Manage the installed software

Step 3.1 - Installing

If you've just installed a program, you can tell GNU stow about it like this:

$ stow lipsum

Now lipsum is stowed, its files are symlinked to /usr/local and you can start using it.

If there are any filename clashes with an existing program, you will get an error and lipsum will not be stowed.

Step 3.2 - Updating

After updating a stowed program, you can tell GNU stow to update the changed files like this (restow):

$ stow -R lipsum

Step 3.3 - Removing

To uninstall a stowed program, use this command (unstow):

$ stow -D lipsum

This will simply remove the symlinks from /usr/local. If you do not plan to use the program later, you can also delete its directory:

$ sudo rm -r /usr/local/stow/lipsum

Conclusion

You can now easily manage programs that you compile and install manually, avoiding conflicts and making uninstallations easy.

There are other alternatives such as checkinstall that you can consider if you want everything to be tracked by your package manager.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue
Try Hetzner Cloud

Get 20€ free credit!

Valid until: 31 December 2024 Valid for: 3 months and only for new customers
Get started
Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more