Linux Package Management

In ancient times, installing software for Linux operating systems could seriously frighten novice users of these operating systems. Downloading sources, dealing with dependencies, which often turned into a non-trivial quest, manually editing configs and other “charms” of installing applications of that time will now seem like a deep anachronism.

Now any self-respecting Linux distribution has the ability to install software using package managers.

A package management system (also sometimes a “package manager” or “package manager”) is a set of software that allows you to manage the process of installing, uninstalling, configuring, and updating various software components.

In this article, we will look at the main package managers that are used in various Linux distributions.

What packages are

Different Linux OS distributions have their own package formats. Here are the main formats:

  • .deb – Debian and derivatives (Ubuntu, Mint, etc.)

  • .rpm – Red Hat and derivatives (CentOS, Fedora, etc.), OpenSUSE

  • .apk – Android

  • .ebuild – Gentoo

Each format has its own advantages and disadvantages. While rpm is compatible with various Linux distributions and provides faster installation and upgrade of packages, it can take a long time to install and upgrade dependencies when installing a large number of packages and has a more complex system for identifying package versions, which can lead to upgrade or installation problems. .

And deb has a simpler system for identifying package versions, which makes them easier to work with, making dependency management faster and more efficient. However, it supports a limited number of Linux distributions, which can create problems when switching to another operating system and may require additional configuration to work with some packages (for example, in case of incompatibility with a certain kernel version).

What does the package consist of

Before we start looking at the principles of working with packages, let’s talk about what packages contain. The package, as a rule, contains the application itself, in a compiled form, that is, in fact, in the form of a binary file.

The package also specifies meta-information, that is, information about other information used by package management tools.

Meta-information is a description compiled according to certain rules that contains the package name, version and build number, information about the developer and his master site, a list of files, their position in the file hierarchy, and a list of dependencies. Also, there may be installation and configuration scripts needed to deploy the application.

In addition to the installation scripts, the package also contains a set of post-installation actions (such as a post-installation configuration). The package also contains a script that is executed if the package is removed.

Let’s see an example of the package structure for Debian. Dependencies are defined in the Dependents field in the package header. This is a list of conditions that must be met for the package to work correctly. This information is used by tools such as apt to install the necessary libraries, utilities, drivers, and so on. in the appropriate versions that satisfy the dependencies of the package being installed. For each dependency, you can limit the range of versions that satisfy this condition. In other words, if we want a libc6 package with a version equal to or greater than “2.15” (“libc6 (>= 2.15)”), then the version comparison operators are:

<=: less than or equal to;

=: equal to (note that “2.6.1” is not equal to “2.6.1-1”);

>=: greater than or equal to;

>>: greater than.

At the same time, it is worth noting that not all packages contain programs, some contain fonts, images, themes, etc.

Dependencies and conflicts

Now it is difficult to imagine an application that does not use third-party libraries and other dependencies in one form or another. That is, any program of any complexity depends on the packages that supply the libraries. In this case, a situation is possible when the package conflicts with the one already installed in the system. The most common reasons for this are that both packages include a file with the same name and path, or provide the same service on the same network port, or interfere with each other.

There are various response options here, in general the package manager will refuse to install a package if it conflicts with an already installed package. However, it is possible that the new package explicitly states that it will “replace” the installed package, in which case the manager will prefer to replace the old package with the new one. But the apt manager always follows your instructions: if you decide to install a new package, it will automatically offer to remove the package that is causing the problem.

Also, in case of a conflict, the following response option is possible: the package manager will signal that the installation of the package will “break” another package (or certain versions of it) and then the user must decide what to do in such a situation. At the same time, different managers will react differently to such a situation. For example, dpkg will refuse to install a package that breaks an already installed package. Instead, apt will try to fix the problem by updating the package that would be broken to a newer version (assuming it’s fixed and thus compatible again).

This kind of situation can arise in the case of updates without backwards compatibility: this is the case when a new one signals that installing a package will “break” another package (or certain versions of it).

Some package formats can be converted. For example, .deb packages can be converted to other formats using the alien utility. As an example, let’s convert a deb package to rpm.

To do this, first install the alien utility:

sudo apt-get install alien

Next, let’s convert the Teamviewer package from deb to rpm. The general format for dealing with alien would be:

sudo alien <package_name>.deb

For our teamviewer example:

sudo alien --to-rpm teamviewer_amd64.deb

Basic Package Operations

Installing packages in all managers is done in a similar way. You must first download the package (.deb, .rpm …), then install the package manually using the command of this distribution (dpkg, rpm, etc.). For example, for dpkg this would be dpkg –i firefox-19.0.deb, and for apt apt-get install firefox.

In this case, all dependencies are resolved and installed automatically.

Updating package lists and packages for apt is done as follows:

apt-get update

Repository update. Downloads only the list of packages, not the packages themselves.

apt-get upgrade

Loading newer versions of locally installed packages.

And the following command is used to remove packages in apt:

apt-get remove [ --purge ] package

If “–purge” is specified, it also removes configuration files.

Where to look for packages

Of course, you can use search engines to search for packages for various distributions, but it is better to use trusted resources so as not to encounter dubious content. So, packages for Ubuntu can be searched on the following resource:

https://packages.ubuntu.com/

And for RPM you can see here:

http://www.rpmseek.com/

Conclusion

In this article, we covered the main points related to working with various packages and package managers. And about standard input / output streams, my colleagues from OTUS will tell on Free Specialization Lesson Administrator Linux.

Similar Posts

Leave a Reply

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