| certifications | open source - Jon Welling
How 5 Package Managers Work on Linux
The very first Linux distribution I used was Fedora back in the late 1990s. At the time, the Linux desktop wasn't nearly as refined as it is today. Gnome and KDE didn't have good graphical interfaces that offered the kind of user experience that offered subtle hints on how to perform basic operating system management like software installation. I understood that in the world of Linux a lot of applications were compiled from source code and installed from scratch. I followed a few guides available back then, learned how to use the Make command, configured GCC for my computer, and installed a few applications, but I routinely ran into dependency issues that drove me insane. I didn't understand that Linux distributions have something called a package manager.
Of course, I no longer have that issue. I've experimented with a lot of Linux distributions since the late 90s from enterprise-level REHL and Ubuntu distros to more niche distributions like Pop OS and Elementary OS — and even the versions of Linux, like Arch and Gentoo, that make Linux newcomers cringe. Though each Linux distribution has its pros and cons, they all have one thing in common: Linux package manager.
What is a Linux Package Manager?
The world of Linux operates a bit differently from Windows or Mac OS. Windows applications tend to act as large, monolithic applications that work within themselves. When you install a Windows application, it will most likely include any of the additional applications or libraries it needs with its install package. Likewise, Windows applications are built on core libraries that are already included with the OS. For instance, if you install Handbrake on Windows, Handbrake will include FFMPEG along with any of the libraries it needs for the UI and the rest of the application to function.
The philosophy behind Linux is more concise, though. Applications are tiny, purpose-built tools. The very nature of Linux lets these small applications work together by piping information into and out of each other. Applications can be strung together in the command-line to work together. Because of this, applications aren't necessarily built with other applications in mind, but they can be chained together to perform complex tasks.
This is why installing applications in Linux can quickly lead to dependency hell without assistance. Some applications depend on other applications to be installed to work properly. To make matters worse, applications may depend on specific versions of other applications. This can create even more confusion since older or newer versions of dependent applications can cause issues. Linux applications don't come with a self-contained installer package that includes these dependencies.
A package manager helps with this. It is the job of a Linux package manager to organize and install applications and their dependencies. A package manager for Linux will also keep track of updates for those applications, too.
5 Types of Linux Package Managers
All Linux distributions have some form of a package manager. They all handle the same job, though:
- Installing applications
- Upgrading applications
- Managing application dependencies
- Removing applications
- Handling OS updates
Depending on the Linux distribution you are using, it will have a different Linux package manager. Here's a quick list of each package manager for popular distributions:
Linux Package Manager
Ubuntu / Debian
How do Linux Package Managers Work?
Though each Linux package manager works slightly differently, they all tend to have a common architecture.
Linux package managers use something called a repository. Repositories are lists of applications. Those lists also include the dependencies for each application as well.
Linux distributions typically have their own maintained repositories. By maintaining their own repositories, each Linux distribution can separate stable software from new or beta software. They can also organize different versions of applications that are only compatible with specific versions of their Linux OS.
Linux users aren't limited to official repositories, though. Linux package managers can ingest repositories from other locations as well. For instance, the popular media content management application called Plex is not included in the official Ubuntu repository. Though Plex offers a pre-built Debian-based binary for Debian and Ubuntu-based Linux OSes, you can also use the Plex repository to install Plex through the Linux package manager (in this case, Apt) as well.
Installing and Updating Applications
Traditionally the Linux package manager is controlled through the command line. Many Linux distributions do have graphical interfaces to work with their package manager, though. These graphical interfaces are typically only included with the graphical desktop versions of Linux distributions. Because server editions of Linux OSes typically do not come with a GUI, we'll be focusing on using the command line for the rest of this article.
First, it's common practice to update repositories and applications before installing new applications through the Linux package manager in the Linux OS. We'll use Apt as an example of this going forward. We'll also explain a couple of the key differences between some of the Linux package managers, too. So, let's use Apt to update the package manager repositories and applications first.
Sudo apt-get update
First, note that we used the Sudo command first. This elevates privileges for the Apt application. This way, Apt has Root privileges. This is needed since more often than not pieces of applications are installed in parts of the OS that require elevated privileges to interact with. Likewise, Apt will also set things like environment variables if an application requires that. This is true for other Linux package managers, too.
Next, we called the Apt application itself. Apt has a couple of variants but all work the same way. In this case, we could substitute Apt-get for simply Apt or Aptitude.
Finally, we use the Update flag. This tells Apt to update the repositories. To be clear, what happens here is that the Linux package manager keeps a local cache of the package manager's repository lists locally on the computer. The primary repositories, along with the applications in it, are stored on servers elsewhere.
Updating Linux Applications
Now that we updated our repository lists, we should update applications. Though this isn't required, it is good practice. We'll do that using the following command:
Sudo apt-get upgrade
This time, we used the upgrade flag instead of the update flag. This flag tells the Apt Linux package manager to install any updates for applications currently installed on the computer. This also installs updates for the OS as well. Note that this does not upgrade applications. It simply installs updates.
Installing Linux Applications
Finally, let's install an application. Let's say that we want to install the Apache webserver. We'll use the following command:
Sudo apt-get install apache
Note that we didn't include any application version numbers here. That's because the Linux package manager keeps track of this for us. Each Linux distribution keeps track of which versions of applications are compatible with the current OS installed. In this case, the package name 'Apache' denotes a certain version of the Apache2 web server listed in the repository.
Typically, if you try and install an application with an incorrect package name, the Linux package manager will attempt to give you a few recommendations of packages with similar names. This does not always work, though. In that case, you'll need to use the search function for your package manager of choice to search a repository for a package name or simply look it up online.
After initiating that install command above, Apt (along with most other Linux package managers) will list the application (and versions) along with its dependencies. Unless the package manager is told to force installations, at this point the package manager will prompt the user for confirmation to install the requested package along with its dependencies. After confirming, the package manager will handle the process of downloading packages, installing and configuring them, and performing any additional functions (like defining environment variables) if needed.
There's a big difference in how some package managers handle applications
Here's a big difference in how some Linux package managers work. Package managers like Apt or Yum catalog pre-compiled binaries for applications. These binaries are only specific to the distribution, distribution version, and processor being used in a system. Otherwise, they are generic application builds.
On the other hand, package managers like Pacman or Portage download the source code for an application (instead of a pre-built binary), compiles that source code, and then handle the rest of the installation process. This is because distributions, like Gentoo and Arch, are built around the idea of being highly configurable. You can build your Linux kernel and OS and tune it to the exact hardware in your computer making it a very lean and fast system. So, Pacman and Portage need to compile applications against your specific build environment for your computer.
Upgrading Applications and the OS
Finally, we can upgrade our OS and applications as well. In the case of Apt, we'll use the following command:
Sudo apt-get upgrade world
The World flag in this case tells Apt to upgrade software altogether instead of simply updating it. You'll use this command to move between versions of a Linux OS as well. For instance, if you wanted to upgrade from Ubuntu 18 to Ubuntu 20, you would use that command above.
Each Linux package manager has a different command for this process, but they all generally work the same way.
What's in a Linux Package Manager?
Linux package managers are a great tool to both build and maintain a computer system. Because of the Linux package manager, it's far easier to install and manage applications, like Apache and PHP, on Linux than it is on a platform like Windows.
The idea of a package manager is spread beyond the world of Linux. Mac OS uses its own package manager to install and maintain itself. There are 3rd party package managers available for Windows like Chocolatey. Even Microsoft has come to recognize the power of package managers and will be moving both the Windows Store and Windows Update to a package management system soon. Within the next year, both the Windows Store and the Windows Update Control Panel snap-in will be nothing more than front-end GUIs for a new Windows package manager according to Microsoft.