Often Linux users need to install additional software (applications) to use in their day-to-day Linux activities. Linux bundles these applications and files needed to run them as packages. Various Linux distributions have different package management systems which more of work on the same concepts according to my experience.
This article will cover basic package management skills in major Linux distributions Debian and Redhat systems. With that, I would say package management is a useful skill set for regular Linux users as we often need to install this or that.
This article will cover a high-level overview of package management in mentioned distributions and probable examples where vital.
Package management consists of low-level and high-level package management tools as explained below:
Low-Level Package Management Tools
Low-level package management tools handle the backend package management tasks such as; building, installing, upgrading, and removing package files.
Packages installed using low-level utilities are usually already bundled/packaged as;
.deb for Debian systems
.rpm for red hat systems.
As much as low-level tools handle installation, one major downside of this is they do not install corresponding dependancies needed for an application if any.
Low-level tools are as follows:
rpm for Red Hat systems.
The basic rpm command syntax is:
rpm [action] options [PACKAGE..]
dpkg for Debian systems and its derivatives
The basic dpkg command syntax is:
dpkg [option…] action [PACKAGE…]
High-Level Package Management tools
High-level package management tools handle the frontend package management. They resolve package dependencies during installation and can perform package metadata searching. High-Level Package Management tools also perform installation or removal of packages usually by invoking the low-level tools.
Red hat systems often use different high-level package tools which ideally work on the same concept and commands can be used interchangeably in some systems.
High-level tools are as follows:
yum (Yellowdog Updater) or dnf (Dandified yum) for Red Hat systems. yum is used on older RHEL systems while newer systems have adopted the use of dnf. dnf was developed to solve performance and memory usage of the yum package manager. It is also important to point out that systems using dnf also have the ability to use yum which is usually linked to the dnf tool.
The basic yum command syntax is:
yum [options] [command] [PACKAGE…]
apt (Advanced Packaging Tool) for Debian systems and its derivatives. It also compromises of aptitude which will not be covered as much in this article.
Repositories are defined application storage locations (remote servers) configured on Linux systems where high-level package tools retrieve and install applications from.
For bundled packages, they can be downloaded and installed using either low-level or high-level package tools. To use high-level tools, packages are installed from repositories. As such it’s always important to have correct repositories and in some cases most updated repositories. More than one repository can be configured on a system. Often configured repositories do not have applications being sought to be installed hence a user might be required to configure repositories for the installation.
Repositories can be configured manually by editing the repository configuration files or using specific high-level commands. When adding repositories manually the public key also needs to be imported manually to the system which can be done on the files or using commands.
. Using Files
apt repositories are configured on /etc/apt/sources.list. Additional repositories can be configured on /etc/apt/sources.d saved with a .list extension.
The format used on Debian sources list is:
deb http://site.example.com/debian distribution component1 component2 component3
deb-src http://site.example.com/debian distribution component1 component2 component3
An example of adding an example repo repository:
yum repository files are held at etc/yum.repos.d/ saved with a .repo extension. The file format of repository files varies and RHEL have detailed documentation on how to set up a repository with the basic format being:
Often additional repositories are added using this way. The files have a format to be followed when setting them up depending on the Linux distro. Major vendors provide this configuration for users for easier installation of softwares. Below is an example of setting up a repository for installing a specific version of MySQL, i.e MySQL 5.7:
# Enable to use MySQL 5.7
name=MySQL 5.7 Community Server
2. Using Commands
Commands can be used to add or remove repositories.
Use cases for commands usage to configure repositories;
a. List repositories
List enabled repositories
To show disabled repositories, list all repositories;
yum repolist all
dnf repolist all
For debian to list enabled repositories, use the grep hack below;
grep ^[^#] /etc/apt/sources.list /etc/apt/sources.list.d/*
The command basically strips out commented repositories and lists enabled repositories.
b. Add Repository
To add repositories:
yum config-manager –add-repo [repository_url]
dnf config-manager –add-repo [repository_url]
To enabable repository;
yumconfig-manager –set-enabled repository-url
To disable repository;
yum-config-manager –disable [repository_url]
dnf-config-manager –disable [repository_url]
Occasionally repository can be installed using yum or dnf command. The example below installs the famous EPEL repository on CentOS 8:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
In some cases, after installing a repository, packages can be enabled or disabled from it. The example below installs remi repository and enables PHP 7.2 :
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
yum-config-manager –enable remi-php7.2
To add a [non standard] repository in Debian requires the package named software-properties-common which is not installed by default in most cases and can be installed by running the command;
apt install software-properties-common -y
Once installed, to add a repository;
[repository_name] can either be a regular repository entry using the format of apt sources.list file or a PPA repository.
a) To add wine application repository
apt-add-repository “deb http://dl.winehq.org/wine-builds/ubuntu/ $(lsb_release -cs) main”
b) Adding the famous PPA repository (Personal Package Archives) which follow the command syntax add-apt-repository ppa:<ppa_name>. To add libreoofice ppa as an example;
Alert! PPAs are always provided by the communities which could pose a security risk, always be careful with these
For more info on how to add repository using add-apt-repository command, use the command option –help
To remove a repository use -r option of apt-add-repository command;
apt-add-repository -r [repository_name]
Adding repository keys:
Often after adding repositories you need to import their public keys which can be done using apt-key command:
a) Add keys manually from keyservers
apt-key adv –keyserver keyserver.ubuntu.com:80 –recv-keys XXXXXXXX
- adv – pass advanced options to gpg
- –keyserver – to specify keyserver url
- –recv-keys – specify key (XXXXXXXX)
apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 9DA31620334BD75D9DCB49F368818C72E52529D4
b) Downloading the keys using wget or curl and importing the keys with apt-key command:
curl -L https://key-url/repo-key.asc | apt-key add –
wget -qO – https://key-url/repo-key.asc | apt-key add –
After adding repositories, to install applications from newly added repositories, the package index must be updated:
Installation can be done from bundled packages or pulling packages with their dependencies from enabled repositories.
To list all installed Packages
Rhel: rpm -qa
Debian: dpkg -l
Query information about a specific package (check if a package is installed)
Rhel: rpm -q [package_name]
dpkg -L [package_name]
dpkg -s [package_name]
dpkg -l [package_name]
Rhel: rpm -qa | grep -i [package_name]
Debian/Ubuntu: dpkg -l | grep -i [package_name]
Useful if you do not know exact package name
Installing and Upgrading Packages
Bundled packages can be installed either using low-level or high-level package management tools
a) Installing a package from precompiled files i.e (*.deb or *.rpm)
Before installation of rpm bundled packages is a good practice to verify the PGP signature of the package. This is done using the –checksig option of rpm command.
rpm –checksig package.rpm
rpm install command syntax is as follows;
rpm -i|–install install-options [package…]
A simplified command for installing package.rpm;
rpm -ivh package.rpm
package.rpm can also be the url of the package i.e.
rpm -ivh https://example.com/package.rpm
-i – install a package
-v – verbose output
-h – prints the hash progress mark bar as the package archive is being unpacked.
Oftenly rpm packages are bundled with required dependencies or the user has to pre-install them. Using high-level package management utilities to install rpm bundled packages attempts to resolve the dependencies:
yum install /path/to/package.rpm
dnf install /path/to/package.rpm
To upgrade an RPM package, use -U (–upgrade) option instead of -i. If the package is not installed it will be installed:
rpm -Uvh package.rpm
-F (–freshen)option upgrade packages, but only ones for which an earlier version is installed unlike the -U option which installs the package if not available:
rpm -Uvh package.rpm
More install and upgrade options of rpm command can be found on rpm man pages or runman rpm on the terminal. An example to ignore dependancy checks when installing or upgrading a package, use the option –nodeps
To install bundled .deb packages, use the i or –install option;
dpkg -i package.deb
To examine the contents of a dpkg file use the -c or –contents option;
dpkg -c package.deb
After installing a package one might need to re-configure the settings. This can be achieved by the dpkg-reconfigure command;
Using apt to install a bundled .deb package:
apt install /path/to/package,deb -y
More dpkg actions and options can be found on dpkg man pages, run man dpkg on the terminal.
b) Installing Packages from Repositories
After setting up repositories as covered before, packages can be installed from the repositories using high-level package management utilities, i.e yum, dnf, apt
To search the repositories for a package:
yum search package_name_search_string
dnf search package_name_search_string
To search all fields, including descriptions use search all option
To install the package:
yum install package_name -y
dnf install package_name -y
To install a list of packages:
yum install package1 package2 package3 packageX -y
dnf install package1 package2 package3 packageX -y
To check information about the package:
yum info package_name
dnf info package_name
yum command also provides a funcionality of attributing a file to the package which owns the file using the provides option:
dnf provides /file/path
yum provides /file/path/
yum provides /etc/my.cnf
To reinstall a package:
yum reinstall package_name
dnf reinstall package_name
To update installed packages:
Update option updates every installed package and keeps obsolete packages if any. Upgrade option tends to remove these obsolete packages in addition to updating installed packages
yum update is the safer option to avoid the risk of removal of any packages that the system might still be using.
To update a specific package:
yum update package_name -y
dnf update package_name -y
upgrade option can be used _interchangeably with update option above.
dnf and yum provide the ability to install/update a group of packages using the groupinstall/groupupdate actions of yum,dnf respectively:
To list installed and available groups from repositories:
Installing/updating group packages:
yum groupinstall ‘packages_group_name’ -y
yum groupupdate ‘packages_group_name’ -y
dnf groupinstall ‘packages_group_name’ -y
dnf groupupdate ‘packages_group_name’ -y
yum groupinstall ‘Development Tools’
To install a package from a specific repository use –enablerepo option specifying the repository;
yum –enablerepo=repository_name install package_name
dnf –enablerepo=repository_name install package_name
yum –enablerepo=epel install php
To get more information on dnf and yum command options check their man pages; man yum, man dnf
To list all available packages;
To install a package, one might need first to search for the package availability which can be done using search option of apt command:
apt search package_name_search_string
apt-cache command is a good alternative to searches for packages:
apt-cache search package_name_search_string
apt-cache pkgnames package_name_search_string
search – searches for package names and their short descriptions
pkgnames – search for specific package names with no descreption.
A quick hack to check the availability of a package is to list all available packages and grep for the package in question, apt list | grep package_name
To install a package;
apt install package_name
To auto sccept all prompts during installation use the -y option with install command, apt install package_name -y
To install several packages just list them:
apt install package1 package2 package3 packageX -y
The install command also upgrades installed packages if run and a new version of the package is available. To prevent already installed packages from upgrading use the –no-upgrade option
apt install package_name –no-upgrade
To show package information:
apt-cache show package_name
To upgrade all installed packages with available upgrades from configured repositories:
apt upgrade -y
While upgrade option of apt does the installation of newly available softwares, it does not remove or install any packages that satisfy some dependencies. dist-upgrade is an enhanced version apt upgrade command whereby it installs and removes packages to satisfy dependencies during an upgrade.
apt dist upgrade -y
To upgrade a specific installed package:
apt install package_name –only-upgrade
For more information on apt install and other commands with the options, check their apt man pages; man apt.
c) Install Specific Version of Packages
In some use cases, one might need to install a specific version of a package from repositories. The usual behavior of repositories is it installs the latest version available on the repositories.
First list the available versions of the package:
apt list -a [package_name]
yum list –showduplicates | grep [package_name]
dnf list –showduplicates | grep [package_name]
yum –showduplicates list [package_name]
dnf –showduplicates list [package_name]
Proceed to install desired version in the fomart:
apt install package_name=<version_info>
yum install package_name-<version_info>
dnf install package_name-<version_info>
Examples of installing a specific version of a package:
Install a specific version of apache webeserver i.e httpd on RHEL and apache2 on Debian derivative (Ubuntu).
yum install httpd-2.4.6-95
apt install apache2=2.4.41-4ubuntu3.10
To only uninstall a package leaving configaration files and dependencies use the command(s):
apt remove [package_name] OR dpkg -r [package_name]
yum remove [package_name] -y
dnf remove [package_name] -y
yum groupremove ‘packages_group_name’ -y
dnf groupremove ‘packages_group_name’ -y
To remove a package, configuration files and erase all unused dependencies use the following command(s) :
apt remove –purge [package_name] OR dpkg -p [package_name]
The explanation for apt uninstallation options used above:
remove -> Only deletes the software, retains the configuration files.
purge/–purge -> Removes the program and config files
autoremove -> Removes orphaned or unnecessary(unused) dependencies
clean ->To delete old/outdated packages cache.
yum autoremove [package_name]
yum logs can be located at /var/log/yum.log or /var/log/message
Install, upgrade and removal of package logs are located at /var/log/dpkg.log regardless of whether they were installed using dpkg or apt.
For apt specific logs, they can be found at /var/log/apt i.e. history.log and term.log
To view rotated logs, use zcat or zgrep…
Handling Broken Installations
Often installation/upgrade can be interrupted one way or the other. This leads to broken installations which require fixing before updating the system or doing additional installations. Often the package managers will print out an error and possible fix for the broken installation.
To fix broken packages:
apt –fix-missing update
Force the installation of the broken packages using the -f option of apt command. apt automatically searches for the broken package installations and reinstalls them afresh from repositories.
apt -f install
dpkg can also be used to solve broken packages by reconfiguring all unpacked packages which have not yet been configured using the command:
dpkg –configure -a
yum and dnf have great capabilities when it comes to dealing with broken package installation. A quick hack to dealing with broken package installations is reinstalling the package:
dnf –refresh reinstall package_name
This article has covered an introduction to common concepts of package managers for installation, upgradation, and removal of applications on the 2 major Linux distributions. If ever in doubt always reference the man pages, and google is always a friend.
https://linux.die.net/man/8/rpm#:~:text=Install and Upgrade Options
https://man7.org/linux/man-pages/man1/dpkg.1.html#:~:text=dpkg is a tool to,and zero or more options.