Where should I store source downloads for installation?

I used to download everything to /tmp, because after make; sudo make install I usually don't need those files anymore.

But now I realized the only way to uninstall programs installed from source, is to use make uninstall (when available). So I should probably keep my downloads in case I need them later.

So where should I store them? Is there a designed place for that in linux?


Solution 1:

The location defined by the Filesystem Hierarchy Standard to keep source code is /usr/src. I suppose you could also use /usr/local/src, as that is a bit more descriptive of where the software came from (that is, you built it; the distro didn't).

Note, however, that the FHS actually mentions that source code should not be built from this directory, likely because you're not supposed to compile things as root, so I suppose that you'd move the source tree there after installation. In practice, though, I don't bother; I keep everything I build in ~/Code, which is on a roomier partition. Basically, there isn't a widely accepted convention; you just do what works for you.

You should also look at checkinstall, a great little piece of software that makes a rudimentary package from a command. (It will probably be in your distribution's repository.) Essentially, instead of running

sudo make install

you would run something along the lines of

sudo checkinstall make install

which quizzes you about the package you're making, watches make install install everything, then builds a package that can then be cleanly installed and uninstalled with a package manager. I believe that checkinstall can build packages for dpkg-based systems (Ubuntu, Debian, etc.), RPM-based systems (Fedora, RHEL, etc.) and Slackware-based systems. If you're running Arch, don't bother with checkinstall; instead, consider using a PKGBUILD.

Hope that helps!

Solution 2:

There is not designated place for source files; everybody has his or her own habits.

However, consider these three options:

  1. In roots homedir (works, but it is on / which is usually rather small).
  2. /usr/local/src/ (or actually anything under /usr/local/
  3. Install via a package and use the package manager to uninstall.

For long term maintenance I really recommend option 3. Even if you have to build the packages yourself (from source). In which case you do get to: untar / configure / make / make package via some syntax depending on your package choice / install package