Regardless of the package manager you’re using, you have two ways of installing programs on Linux. You either use a pre-built package, or compile it yourself. These days, the former usually wins out by default. There are, however, times when you should consider the alternative.
What Are Binary Packages?
Installing programs on Linux is usually quite different to installing on Windows. Rather than get the installers off a vendor’s website, the files are retrieved from a repository of programs, usually tailored for your operating system.
Files for separate programs are stored in an archive format. This bundles everything into a single file for easy access later. For example, Debian uses the DEB format to store their programs. These bundles are called binary packages.
Installing requires a special program to extract these files and put them onto your computer. That is to say, your package manager (e.g. APT, Yum, and so on). It also does other useful things, such as keep track of what files you have installed, and manage software updates.
Where Do Packages Come From?
All software is written in lines of text called source code. They’re written in specific programming languages, such as C or C++. Generally however, you can’t just bundle that into an archive and call it a package. These lines need to be translated into a language your computer can understand and execute.
This process is called compiling, the end result creating binaries which your computer can run. It’s these binaries that are stored together inside a package, along with other things such as configuration files.
What Is Installing “From Source”?
Compiling source code isn’t just for making packages. In fact, creating such an archive from it is not even necessary. Basically, installing a program “from source” means installing something without using a package manager. You compile the source code and copy the binaries to your computer instead.
Most of the time, you can download a project’s source code from hosting services such as GitHub or BitBucket. Larger programs might even host it on a personal website. The code will usually be zipped up in an archive format (also known as a source package).
A special set of tools helps to automate the building process. On Linux desktops, this usually comes in the form of a command line program called make. Source code written in different languages need specific compilers and commands to change them into binaries. The make program automates this process.
To do this, programs provide make with a makefile that tells it what to do and compile. These days, it’s usually automatically generated by special software such as CMake. This is where the user comes in. Because from here, they can specify exactly what features they’d like compiled into their own software.
For example, the command below generates a configuration file for the Calligra Office Suite using CMake. The file created tells the make program to only compile the Writer component of Calligra.
cmake -DPRODUCTSET=WORDS -DCMAKE_INSTALL_PREFIX=$HOME/kde/inst5 $HOME/kde/src/calligra
Having done this, all a person has to do is run the make tool to compile and copy the results onto their computer. This is done in the following way:
make make install
While this is the general pattern for compiling programs, there are many other ways to install source packages. Gentoo Linux, for example, has a built-in way of handling this, making the process much faster and easier. Along with this, building binary packages takes a few more steps than just the above commands.
Benefits of Using Binary Packages
If you’re using Linux, chances are that the programs you have installed were pre-compiled. These days, it’s much more common than using source packages. There are a few reasons why that’s the case.
Easier to Manage
Binary packages contain much more than just compiled installation files. They also store information that makes it easy for your package manager to keep track of all your programs. For example, DEB files (the package format for Debian and Debian derivatives) also contain important information such as what other software the program needs to run, and its current version.
This makes packages much easier to install. You don’t need to worry about what other files you need to install to make a program run for example. Since your package manager can read that information from the package itself, it handles all that automatically.
Compare this to installing programs from source. Unless you compile the code into a binary package of its own, you will be in charge of managing that software. You’d need to keep in mind what other programs you need to make it work, and install them yourself.
Package repositories tend to test their binaries for problems, and do their best to fix them when they appear. This can lead to improved stability of programs, something a person who installed from source might miss out on.
For example, there are a number of packages in Debian’s repositories that have fixes applied to them. This can even include large programs such as web browsers!
Along with this, packages usually must adhere to a strict set of rules to help ensure they’ll run on your system. Both Debian and Ubuntu have a policy manual for example, as do many other Linux operating systems.
Some programs also rely on different versions of the same software dependency to run. Package repositories do their best to resolve these conflicts so you don’t have to worry about this.
Benefits of Compiling Source Packages
Installing programs from source isn’t something that everyone needs to do. In fact, it’s best if you stick with binary packages. Even so, there are still some advantages to using this slightly more involved way of installing programs.
One disadvantage of making programs more reliable is that it takes time to improve and fix. As a result, this can lead to you using older versions of software. For people who want the latest and greatest, they might even prefer a bit of instability in exchange for it.
While there are Linux operating systems which cater for this need without compiling programs, they do have a few drawbacks. For example, software that doesn’t frequently release set package versions are harder to keep up to date in a repository, than installing from source.
This is because binary packages are usually made from official releases of programs. As such, changes between these versions are usually not taken into account. By compiling your own software from source, you can benefit immediately from these changes.
It’s also possible that your Linux operating system doesn’t have the software you want pre-made for you. If that’s the case, installing it from source is your only option.
Pick and Choose
Another benefit to using source packages is that you gain more control over the programs that you install. When installing from a binary repository, you’re restricted in the ways you can customize your packages.
For example, look at FFmpeg, the command-line-based audio and video converter. By default, it comes with a huge number of features, some of which you might never even touch. For instance, JACK audio support is available in FFmpeg, even though this software is usually used in production environments only.
Compiling FFmpeg allows you to remove the things you don’t want from it, leaving it lighter, and tailored to your needs. And the same applies to other heavyweight programs.
When resources are scarce, removing features can be a great way of lightening the load. It’s no wonder that Chrome OS, found on many low-end computers, is based off Gentoo Linux. Gentoo, being source-based, compiles a lot of its software, potentially making these systems run much lighter.
Why Not Install With Both?
While you probably won’t want to compile packages on a daily basis, it’s something useful to keep in mind. If ever you don’t find your software repositories good enough, remember that there’s another, older way of getting things installed.
Have you ever had to compile software before? Why?
Image Credit: Andrii Symonenko via Shutterstock.com