Compiling programs in Fedora

Say you want to install a program in Fedora…

Before Compiling:

Many programs are available easily in the Fedora repositories via yum.

  • If you don’t already have a graphical package management tool, then install PackageKit or yumex.
  • If you prefer the command-line, then (as root / under sudo) use:
    >yum search <program>
    to see if a pre-built package (RPM) is already available. Then:
    >yum install <program>
    to install it. This is the easiest way to install software, and has the nice benefit of automatically resolving dependencies, integrating into the desktop, and making updating, uninstalling, checking, and reinstalling programs just as easy.
  • To improve results, run:
    >yum install rpmfusion-free-release rpmfusion-nonfree-release
    before running the above commands.  This adds a couple of important repositories to the search list, greatly increasing the chance of finding what you are looking for.
  • If you don’t find the program you want this way, don’t give up yet.  There are a few other package repositories around that you should check for pre-built packages.  Examples: pbone and rpmfind.  If you find a suitable package there, then download it and install using:
    >yum install <.rpm file>
  • If you still don’t find the program, then check the project’s web site to see if they offer any solutions for Fedora and/or RPM-based package managers.  Many do.  They may offer a yum repository, .rpm file, or perhaps a source file (eg, .src.rpm) from which a .rpm file may be generated using rpmbuild.  If they offer a package for a non-RPM package manager (eg, apt-get), then you may be able to convert it to .rpm using alien.
  • Failing a .rpm solution, some programs offer their own installers (ie, they come with an install.sh script), which you could try.  Note however, that without a .rpm, uninstalling such software may not be straightforward.  If the package doesn’t include an uninstall script as well, then my personal practice is to install it under a non-root user space only – see “Building an RPM” below if that’s not an option.
  • Finally, if no other solutions exist, then you might resort to compiling.

Compile Process:

The compile process in principal is straightforward.  Do this as a non-root user:

  1. Download the source code – typically a “tar ball” with a .tar.gz extension, although other types of files may come up as well (.tar.Z, .bz2, etc).  Typically any Linux opensource project web site will provide such a file.  Some projects use subversion or git, and can be downloaded using the svn or git command, respectively.
  2. Extract it using:
    >tar xzvf <program>.tar.gz
    for typical packages – other compression formats will require different commands.  Before doing this, you may also want to check that the package will extract into a directory, otherwise, you might want to create a directory for it so it doesn’t make a mess.
  3. Go into the directory containing the extracted files, typically:
    >cd <program>
  4. Technically, if there is a README or INSTALL file (or some other type of documentation), then you should read that first.  However, the process is typically the same.  If there is a script in that directory called “configure”, then you should probably run that first:
    >./configure
    This usually creates a Makefile, which is used for the rest of the work.
  5. Then, run:
    >make
    to compile the program.  This is the hardest step – see “Resolving Dependencies” below.
  6. If you want to install the program, then you can run (as root / under sudo):
    >make install
    However, personally, I prefer to leave non-RPM programs in user space, and run them from there whenever possible, so I skip this step – see “Building an RPM” below if that’s not an option.

Resolving Dependencies:

Ideally, the project’s web site should document dependencies, so that you can resolve those ahead of time.  In practice though, you will often run into errors during the compile (make) process.  Having the right tools to compile software with would be the first step.  Typically that’s gcc and make, or perhaps others such as gcc-c++ and cmake.  The second step is installing the source code (development) packages for libraries and other software dependencies.  Typically these are packages called <library>-devel.  Whatever the dependencies are, here is a simple generic process that you can use to resolve them:

  1. Run the make command.
  2. Read the error it generates, and look for the name of a missing file that is needed to proceed.
  3. Run:
    >yum whatprovides */<missing file>
  4. Install the missing package listed in the results.
  5. Go back to step 1.

Once make runs clean, most of these dependencies can probably be uninstalled.

Note: If you run into version problems (ie, you have the right packages but the wrong version), then things can get more complicated, and often times impossible to fix without a lot of manual intervention.  I would look for a version of the program compatible with your distribution (kernel) first, and attempt to resolve version conflicts only as a last resort.

Building an RPM:

Instead of running make install to install the program, consider making an RPM of it.  Using make install will install the program, but unless a make uninstall feature is available, it will not be easy to uninstall later (if it doesn’t work for example).  As well, if you ever plan to install it again, on another machine say, or even on the same machine following an uninstall, or a catastrophic failure, then you will have to resolve dependencies manually again.  With an RPM and the createrepo command, you can automate this process for the future.

Have a look at CheckInstall for a simple way of building an RPM from a compiled package.  For building Perl modules, try cpanspec. Alternatively, creating a .spec file manually for generating an RPM takes some work.

Windows Software:

And what if the program you want is not available for Linux?  Then try WINE or VirtualBox.

One thought on “Compiling programs in Fedora

Leave a Reply

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