There are two broad ways of installing programs on Linux. You either use a pre-built package, or you compile the program yourself. These days, the former usually wins out by default, but there are times when you may want to consider compiling from the source code.

What Are Binary Packages?

DEB Package Format

Installing programs on Linux is usually quite different from the traditional way of installing software on Windows. Rather than downloading an installer off a vendor's website, the files come from a repository of programs usually tailored to your Linux distribution. You access this repository using a Linux package manager or an app store.

The files that make up the programs in these repositories come in an archive format. This bundles everything into a single file for easy access and distribution. Debian, for example, uses the DEB format to store and distribute programs. These bundles are called binary packages.

How to Read Binary Code

You need a special program to extract these files and install them onto your computer, typically your package manager or app store. These tools also perform other useful functions, such as keeping track of what files you have installed, and managing software updates.

Newer package formats like Flatpak and Snap work across different versions of Linux, but they still consist of pre-compiled binary programs. Both require a graphical app store or command-line-based package manager for installation.

What Is Source Code?

All software consists of lines of text known as source code, written in specific programming languages, such as C or C++. You generally can't just bundle this source code 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, and the end result creates binaries that your computer can run. The difference between packages and software is that software binaries are stored together inside a package, along with other things such as configuration files.

What Is Installing "From Source"?

Makefile for Emacs

Installing a program "from source" means installing a program 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, GitLab, or Bitbucket. Larger programs might even host source code 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 help automate the building process. On Linux desktops, this often 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.

For this automation to work, programs provide make with a Makefile that tells it what to do and compile. These days, the Makefile is usually automatically generated by special software such as CMake. This is where you come in. From here, you can specify exactly what features you want compiled into your software.

Building "From Source" Example

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. But building binary packages takes a few more steps than just the above commands.

Benefits of Using Binary Packages

If you're using Linux, someone more than likely pre-compiled the software you have installed. This has become much more common than using source packages. But why?

1. Binary Versions Are Easier to Manage

the deb package format

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, as you don't need to worry about what other files you need to successfully make a program run. Your package manager can read that information from the package itself and downloads all the necessary dependencies automatically.

When 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 will need to keep in mind what other programs you need to make it work and install them yourself.

2. Binary Versions Have Improved Stability

The people who maintain repositories for your package manager tend to test binaries for problems and do their best to fix those that appear. This can lead to improved stability, since package maintainers may spot something a person who installed from source might miss out on.

Plus packages usually must adhere to a strict set of rules to help ensure they will run on your system. Both Debian and Ubuntu have a policy manual, for example, as do many other Linux distributions.

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.

Benefits of Compiling Source Packages

Installing programs from source isn't something that everyone needs to do, as it's generally easier to maintain your PC if you stick with binary packages. Even so, there are still some advantages to using this slightly more involved way of installing programs.

1. Source Code Offers Latest Software

One disadvantage of making programs more reliable is that it takes time to improve and fix. Sometimes there is a binary available, but the source code is later. For people who want the latest and greatest, they might even prefer a bit of instability in exchange for newer software.

While there are Linux operating systems that cater to this need without compiling programs, they do have a few drawbacks. For example, software that doesn't frequently release set package versions is 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 such changes.

It's also possible that your Linux operating system doesn't have the software you want pre-made for you. In the past, this would make installing it from source your only option. Universal package formats have changed this. Flatpak and Snap packages also generally receive updates much faster than system repositories. But there are still times when compiling is the only way to get the goods.

2. You Can Pick and Choose

features of ffmpeg

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 only used in production environments.

Compiling FFmpeg allows you to remove the things you don't want, leaving it lighter and tailored to your needs. 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 ChromeOS, found on many low-end computers, is based on Gentoo Linux. Gentoo, being source-based, compiles a lot of its software, potentially making these systems run much lighter.

Why Not Use Both Binary and Source Packages?

While you probably won't want to compile packages on a daily basis, it's something useful to keep in mind. That said, with new universal package formats available from sites such as the Snap Store and Flathub, you're less likely to need to build from source to get the latest software.