×

Search anything:

Linux Package Management

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

The word Linux will refer to any operating system that uses the Linux kernel

Package management entails installing, upgrading, configuring, and removing software. Besides the tasks above, package management tools also facilitate software dependency resolution.

A dependecy is an additional package required by a principal package to function properly.

There are roughly three Linux distribution families:

  • Debian
  • RedHat
  • Slackware

Each distribution family above has its own package management system. Debian has APT and DPKG. RedHat uses RPM and DNF which replaced YUM(though still available in some distributions),and Slackware uses SLACKPKG.

In this article, we shall only discuss package management tools for the Debian and RedHat families.

Package management tools are classified into the following:

  • High level
  • Low level

Low level package managers

In this category we have dpkg and rpm.

  • They dont automatically download and install packages. ie They work locally.
  • They donot do dependency resolution. If package A depends on package B, the installation will fail if package B is not already installed.

Installing a package.

Before installing packages with low level tools, the package file has to be downloaded first.

Debian:
dpkg -i <package-file>

RedHat:
rpm -i <package-file>

The receding commands will install keepassxc password manager
dpkg -i keepassxc_2.6.2+dfsg.1-1_amd64.deb

rpm -i keepassxc-2.7.1-13.fc38.x86_64.rpm

Upgrading a package

Before upgrading a package, a newer version of the package file has to be downloaded first.

Debian:
dpkg -i <package-file>

RedHat:
rpm -U <package-file>

The following commands will update keepassxc password manager
dpkg -i keepassxc_2.6.2+dfsg.1-1_amd64.deb

rpm -U keepassxc-2.7.1-13.fc38.x86_64.rpm

Removing a package

Debian:
dpkg -r <package-name>

RedHat:
rpm -e <package-name>

The following commands will uninstall bash plus its dependencies.
dpkg -r bash

rpm -e bash

Be careful when removing packages with low level tools.

All the package's dependencies are removed even when there are other packages on the system that still depended on them.

This might break functionality of other packages left on the system. It is recommended to use higher level tools to remove the packages.

Querying the package database

Debian:
dpkg-query --list <package-name-pattern>

RedHat:
rpm -qa | grep -E <package-name-pattern>

The following will list all packages whose names start with bash.
dpkg-query --list 'bash*'
rpm -qa | grep -E '^bash'

High level

  • They do dependency resolution.
  • They can download and install packages.
  • They can work with locally downloaded packages.

Installing a package

Debian:
apt install <package-name | package-file>

RedHat:
yum install <package-name | package-file>

The following commands will install keepassxc password manager
apt install keepassxc

yum install keepassxc

The above commands will download keepassxc package and install it in addition to installing its dependencies.

DNF (Dandified yum) is a replacement for the traditional YUM. DNF and YUM share similar options. All the commands here will work with DNF

Removing a package

Debian:
apt remove <package-name>

RedHat:
yum remove <package-name>

Illustration:
apt remove keepassxc

yum remove keepassxc

Upgrading a package

Upgrading is moving from a lower version of a package to a higher version of the package.
Debian has a package index (local cache) that stores meta data of the available packages that your repositories provide.

Before upgrading a package on debian systems, you have to fetch the latest package index to notify your package manager of new versions of the package.

apt update

Then after that:

apt install <package_name>

On RedHat Distributions
yum update <package_name>

Upgrading all installed packages

Debian:

apt update
apt full-upgrade

RedHat:
yum update

Searching packages

Debian:
apt search <regex>

RedHat:
yum search <string>

The following commands will find packages whose names or description contain the token 'bash'

apt search bash

yum search bash

There is a plethora of options and flags supported by the packagement management tools, However the best place to learn more about the package management tools are the man pages.

man apt
man yum

man dpkg
man rpm

Linux Package Management
Share this