Contents
- Introduction
- Packaging Systems
- How A Package System Works
- Common Package Management Tasks
- Finding A Package In A Repository
- Installing A Package From A Repository
- Removing A Package
- Removing Orphan Packages
- Updating Packages From A Repository
- Listing Installed Packages
- Displaying Information About An Installed Package
- Installing A Package from A Package File
- Upgrading A Package from A Package File
- Determining Whether A Package Is Installed
- Finding Which Package Installed A File
- Summary
Introduction
If we spend any time in the Linux community, we hear many opinions as to which of the many Linux distributions is “best.” Often, these discussions get really silly, focusing on such things as the prettiness of the desktop background (some people won’t use Ubuntu because of its default color scheme!) and other trivial matters.
The most important determinant of distribution quality is the packaging system and the vitality of the distribution’s support community. As we spend more time with Linux, we will see that its software landscape is extremely dynamic. Things are constantly changing. Most of the top-tier Linux distributions release new versions every six months and many individual program updates every day. To keep up with this blizzard of software, we need good tools for package management.
Package management is a method of installing and maintaining software on the system. Today, most people can satisfy all of their software needs by installing packages from their Linux distributor. This contrasts
with the early days of Linux, when one had to download and compile source code to install software. There isn’t anything wrong with compiling source code; in fact, having access to source code is the great wonder of Linux. It gives us (and everybody else) the ability to examine and improve the system. It’s just that having a precompiled package is faster and easier to deal with.
Packaging Systems
Different distributions use different packaging systems, and as a general rule, a package intended for one distribution is not compatible with another distribution. Most distributions fall into one of two camps of packaging technologies: the Debian .deb camp and the Red Hat .rpm camp. There are some important exceptions such as Gentoo, Slackware, and Arch, but most others use one of these two basic systems,
Packaging system | Distributions (partial listing) |
---|---|
Debian-style (.deb) | Debian, Ubuntu, Linux Mint, Raspbian |
Red Hat–style (.rpm) | Red Hat Enterprise Linux, CentOS, Fedora, OpenSUSE |
How A Package System Works
The method of software distribution found in the proprietary software industry usually entails buying a piece of installation media such as an “install disk” or visiting each vendor’s website and downloading the product and then running an “installation wizard” to install a new application on the system.
Linux doesn’t work that way. Virtually all software for a Linux system will be found on the Internet. Most of it will be provided by the distribution vendor in the form of package files, and the rest will be available in source code form that can be installed manually.
Package Files
The basic unit of software in a packaging system is the package file. A package file is a compressed collection of files that comprise the software package. A package may consist of numerous programs and data files that support the programs. In addition to the files to be installed, the package file also includes metadata about the package, such as a text description of the package and its contents. Additionally, many packages contain preand post-installation scripts that perform configuration tasks before and after the package installation.
Package files are created by a person known as a package maintainer, often (but not always) an employee of the distribution vendor. The package maintainer gets the software in source code form from the upstream provider (the author of the program), compiles it, and creates the package metadata and any necessary installation scripts. Often, the package maintainer will apply modifications to the original source code to improve the program’s integration with the other parts of the Linux distribution.
Repositories
While some software projects choose to perform their own packaging and distribution, most packages today are created by the distribution vendors and interested third parties. Packages are made available to the users of a distribution in central repositories that may contain many thousands of packages, each specially built and maintained for the distribution.
A distribution may maintain several different repositories for different stages of the software development life cycle. For example, there will usually be a “testing” repository that contains packages that have just been built and are intended for use by brave souls who are looking for bugs before the packages are released for general distribution. A distribution will often have a “development” repository where work-in-progress packages destined for inclusion in the distribution’s next major release are kept.
A distribution may also have related third-party repositories. These are often needed to supply software that, for legal reasons such as patents or DRM anti-circumvention issues, cannot be included with the distribution. Perhaps the best known case is that of encrypted DVD support, which is not legal in the United States. The third-party repositories operate in countries where software patents and anti-circumvention laws do not apply. These repositories are usually wholly independent of the distribution they support, and to use them, one must know about them and manually include them in the configuration files for the package management system.
Dependencies
Programs are seldom “stand alone”; rather, they rely on the presence of other software components to get their work done. Common activities, such as input/output, for example, are handled by routines shared by many programs. These routines are stored in shared libraries, which provide essential services to more than one program. If a package requires a shared resource such as a shared library, it is said to have a dependency. Modern package management systems all provide some method of dependency resolution to ensure that when a package is installed, all of its dependencies are installed, too.
High And Low Level Package Tools
Package management systems usually consist of two types of tools. Low-level tools that handle tasks such as installing and removing package files. High-level tools that perform metadata searching and dependency resolution.
Distributions | Low Level | High Level |
---|---|---|
Debian style | dpkg | apt-get , apt , aptitude |
Red Hat Enterprise style | rpm | yum , dnf |
Common Package Management Tasks
Many operations can be performed with the command line package management tools. We will look at the most common.
Finding A Package In A Repository
Style | Command |
---|---|
Debian | apt search search_string |
Red Hat | dnf search search_string |
Installing A Package From A Repository
Style | Command |
---|---|
Debian | apt install package_name |
Red Hat | dnf install package_name |
Removing A Package
Style | Command |
---|---|
Debian | apt purge package_name |
Red Hat | dnf erase package_name |
Removing Orphan Packages
Style | Command |
---|---|
Debian | apt autoremove |
Red Hat | dnf autoremove |
Updating Packages From A Repository
Style | Command |
---|---|
Debian | apt update; apt upgrade |
Red Hat | dnf update |
Listing Installed Packages
Style | Command |
---|---|
Debian | apt list --installed |
Red Hat | dnf list --installed |
Displaying Information About An Installed Package
Style | Command |
---|---|
Debian | apt show package_name |
Red Hat | dnf info package_name |
Installing A Package from A Package File
Style | Command |
---|---|
Debian | dpkg -i package_file |
Red Hat | rpm -i package_file |
Upgrading A Package from A Package File
Style | Command |
---|---|
Debian | dpkg -i package_file |
Red Hat | rpm -U package_file |
Determining Whether A Package Is Installed
Style | Command |
---|---|
Debian | dpkg -s package_name |
Red Hat | rpm -q package_name |
Finding Which Package Installed A File
Style | Command |
---|---|
Debian | dpkg -S file_name |
Red Hat | rpm -qf file_name |
Summary
In this chapter, we will looked at some of the command line tools used for package management. While all the major distributions provide powerful and sophisticated graphical programs for maintaining the system, it is important to learn about the command line programs, too.