Today I got thinking about a few rules that I should keep when compiling applications from source. It’s a small list, I’m looking for any feedback you may have. There’s some good ground for discussion here, and depending on which Linux courses you look at, opinions will vary.
For this, I’m also assuming you won’t be making RPM packages out of those source compiles to place in a personal repository (which is overkill for 99% of the cases).
Don’t do it if it’s not necessary
Compiling from source breaks the dependency-lists in yum and aptitude. If possible, don’t try to compile from source but use a package manager to get the packages you need.
Source location & symlinks
- If there’s already a yum/apt-get package installed of the software you’re trying to install from source, make sure to remove that package first! (unless you have a -very- good reason to keep both versions, you are only making it more confusing for yourself)
- Place an exclude in
/etc/yum.conf
to prevent that package from ever being installed via a package manager. - Place all the source code in
/usr/local/src
- Extract the software in a directory containing its specific version (see next point)
- Symlink that specific version to the actual package name to point to the currently active one
For instance:
# ls -alh /usr/local/src/ lrwxrwxrwx 1 root root 10 Nov 30 13:13 php -> php-5.2.14 drwxr-xr-x 18 1002 1002 4.0K Jun 10 2010 php-5.2.13 drwxr-xr-x 19 1005 1005 4.0K Nov 15 09:15 php-5.2.14
That way, you can have all the source code ready in case you need to switch back to a previous version, you use the symlink to point the directory that has now been used to create the current binaries.
- Always try to install the binaries in
/usr/local/bin
or/usr/local/sbin
, try never to install in/usr/bin
or/usr/sbin
. That way, it should be more obvious when a specific binary has been installed from yum/apt-get (when it’s in/usr/bin
or/usr/sbin
) or when it comes from source (everything in/usr/local/*
). If necessary, symlink your/usr/local/bin/my-app
to/usr/bin/my-app
. - Place a note in the /etc/motd that this specific piece of software has been self-compiled with a location to the source
- Always create a “
configure_custom
” file (chmod +x
that) with your configure parameters in your source dir. Even when it’s just a “./configure”, place that in a “configure_custom
” file so we know that there are no parameters needed.
As a bonus, when you start to run make
, consider the concurrency options in make to cut down in your compile times.
I’m curious about any other pointers that are worth keeping when compiling (some of) your applications from source.