Installing and maintaining software on Red Hat–based servers is similar to the Ubuntu server process, just with different tools. Just like Ubuntu, Red Hat uses a package management system to make installing and updating software easy, especially if your server is connected to the Internet. However, if your Red Hat server is not connected to the Internet, there's still a way for you to install and upgrade software using packages.
Red Hat Enterprise Linux, CentOS, and Fedora use the Red Hat Package Manager (RPM) utility to install and manage software. Application files are bundled into an rpm package for distribution. rpm package files have an .rpm
file extension and use a specific naming format as follows:
name-version-release.architecture.rpm
Since software packages are compiled for specific architectures, there are usually multiple rpm packages for each software package. The version
is the program's version number, so you can easily track what version of the software is currently installed and what version is available for download. The release
is the distribution release identifier. Even though rpm packages can be installed on any Red Hat–based Linux system, sometimes packages are compiled for specific distribution environments. Packages created for CentOS normally have a release of el8
. Here's an example of listing some .rpm
files:
# ls -l *.rpm
total 11920
drwxr-xr-x. 2 sysadmin sysadmin 253 Dec 5 10:23 .
drwx------. 3 sysadmin sysadmin 74 Dec 5 10:21 ..
-rwxr-x---. 1 sysadmin sysadmin 1621792 Dec 5 10:21 bash-4.4.19-10.el8.x86_64.rpm
-rwxr-x---. 1 sysadmin sysadmin 5943540 Dec 5 10:21 binutils-2.30-73.el8.x86_64.rpm
-rwxr-x---. 1 sysadmin sysadmin 361000 Dec 5 10:21 curl-7.61.1-12.el8.x86_64.rpm
-rwxr-x---. 1 sysadmin sysadmin 507956 Dec 5 10:21 openssh-8.0p1-4.el8_1.x86_64.rpm
-rwxr-x---. 1 sysadmin sysadmin 713708 Dec 5 10:21 openssl-1.1.1c-15.el8.x86_64.rpm
-rwxr-x---. 1 sysadmin sysadmin 3039264 Dec 5 10:21 zsh-5.5.1-6.el8_1.2.x86_64.rpm
#
Notice that the architecture for each is x86_64
, indicating that the software packages were compiled for a 64‐bit CPU environment.
There are two ways to install rpm packages.
rpm
command‐line toolUsing an automated package management tool is usually preferred. These tools have the ability to connect via the Internet to a software repository to find the requested package and install it, along with any dependent packages. However, there are times when a Red Hat server doesn't have Internet access, such as in secure environments. In those cases, you'll have to download the software rpm packages on a different platform, transfer them to the server, and then install them manually using the rpm
command‐line tool. The following sections cover both methods of installing RPM software packages.
Like the Debian‐based distributions, the Red Hat–based systems have several different front‐end tools available. The common ones are these:
yum
: Used in Red Hat, CentOS, and Fedoradnf
: An updated version of yum
with some additional featureszypper
: Used in openSUSEThese front ends are all based on the rpm
command‐line tool. The following section discusses how to manage software packages using these various rpm
‐based tools. The focus will be on dnf
, but the other packages use similar commands and formats.
To find out what is currently installed on your system, at the shell prompt use the list
option of the dnf
command, as shown here:
$ dnf list installed
Installed Packages
NetworkManager.x86_64 1:1.22.8-5.el8_2 @BaseOS
NetworkManager-config-server.noarch 1:1.22.8-5.el8_2 @BaseOS
NetworkManager-libnm.x86_64 1:1.22.8-5.el8_2 @BaseOS
NetworkManager-team.x86_64 1:1.22.8-5.el8_2 @BaseOS
NetworkManager-tui.x86_64 1:1.22.8-5.el8_2 @BaseOS
PackageKit.x86_64 1.1.12-4.el8 @AppStream
PackageKit-glib.x86_64 1.1.12-4.el8 @AppStream
abattis-cantarell-fonts.noarch 0.0.25-4.el8 @AppStream
acl.x86_64 2.2.53-1.el8 @BaseOS
adcli.x86_64 0.8.2-5.el8 @BaseOS
at.x86_64 3.1.20-11.el8 @BaseOS
attr.x86_64 2.4.48-3.el8 @BaseOS
audit.x86_64 3.0-0.17.20191104git1c2f876.el8 @BaseOS
audit-libs.x86_64 3.0-0.17.20191104git1c2f876.el8 @BaseOS
…
$
There will be lots of packages installed on your server; it usually helps to redirect the output to the more
or less
command to look at the list in a controlled manner. You can also redirect the output to a text file for viewing in a text editor.
dnf list installed > installed.txt
The format of the listing is a little different from the format of the original package names, but you can probably pick out the different components. The package name and architecture are listed first, followed by the version and release. The third column shows what repository category the package came from.
You can also look for a single installed package.
$ dnf list installed bash
Installed Packages
bash.x86_64 4.4.19-10el8 @BaseOS
$
If the package isn't installed, dnf
will tell you.
$ dnf list installed zsh
Error: No matching Packages to list
$
You can then check if the package is available in the software repository by using the list
option with the software package name.
$ dnf list zsh
Last metadata expiration check: 0:00:18 ago on Sat 05 Dec 2020 10:33:03 AM EST.
Available Packages
zsh.x86_64 5.5.1-6.el8_1.2 BaseOS
$
Finally, if you need to find out what software package provides a particular file on your filesystem, use the provides
option.
dnf provides file_name
Here's an example of trying to find what software provided the file /usr/bin/gzip
:
$ dnf provides /usr/bin/gzip
Last metadata expiration check: 0:04:02 ago on Sat 05 Dec 2020 10:32:22 AM EST.
gzip-1.9-9.el8.x86_64 : The GNU data compression program
Repo : @System
Matched from:
Filename : /usr/bin/gzip
gzip-1.9-9.el8.x86_64 : The GNU data compression program
Repo : BaseOS
Matched from:
Filename : /usr/bin/gzip
$
dnf
checked two separate repositories: the local system (denoted by @System
) and the default fedora repository (denoted by BaseOS
). That allows you to easily check whether there's an update available for the file.
Installation of a software package using dnf
is simple. All you need is the install
option, followed by the package name.
dnf install package_name
This installs not only the software package specified, but also any package dependencies. The output will show you the package information, along with any dependent packages required to install, and prompt you to continue the installation.
In most Linux distributions, when you're working away in the graphical user interface (GUI), you get those nice little notification icons telling you a software upgrade to a new version is needed. Here at the command line, it takes a little more work.
To see the list of all the available upgrades for your installed packages, type the following command:
dnf list upgrades
If you see that a particular software package needs upgrading, then type in the following command:
dnf upgrade package_name
If you'd like to upgrade all the packages listed in the upgrade list, just enter the following command:
dnf upgrade
One nice feature in dnf
is the upgrade‐minimal
command. It upgrades a package to the latest bug fix or security patch version instead of the latest and greatest version.
The dnf
tool also provides an easy way to uninstall software you no longer need by using the remove
option.
# dnf remove zsh
Dependencies resolved.
==============================================================================
Package Architecture Version Repository Size
==============================================================================
Removing:
zsh x86_64 5.5.1-6.el8_1.2 @BaseOS 7.2 M
Transaction Summary
==============================================================================
Remove 1 Package
Freed space: 7.2 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64 1/1
Erasing : zsh-5.5.1-6.el8_1.2.x86_64 1/1
Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64 1/1
Verifying : zsh-5.5.1-6.el8_1.2.x86_64 1/1
Installed products updated.
Removed:
zsh-5.5.1-6.el8_1.2.x86_64
Complete!
#
Unlike the Ubuntu apt
tool, dnf
doesn't provide an option to remove the application files but keeps any configuration or data files. When you remove a package, everything associated with that package is removed.
Sometimes as multiple software packages get loaded, a software dependency for one package can get overwritten by the installation of another package. This is called a broken dependency.
If this should happen on your system, first try the following command:
dnf clean all
Then try to use the upgrade
option in the dnf
command. Sometimes, just cleaning up any misplaced files can help.
If that doesn't solve the problem, try the following command:
dnf repoquery --deplist package_name
This command displays all the package's library dependencies and what software package provides them. Once you know the libraries required for a package, you can then install them. Here's an example of determining the dependencies for the zsh package:
# dnf repoquery --deplist zsh
CentOS Linux 8 - AppStream 1.3 MB/s | 6.2 MB 00:04
CentOS Linux 8 - BaseOS 867 kB/s | 2.3 MB 00:02
package: zsh-5.5.1-6.el8_1.2.x86_64
dependency: /bin/sh
provider: bash-4.4.19-12.el8.x86_64
dependency: coreutils
provider: coreutils-8.30-8.el8.x86_64
dependency: grep
provider: grep-3.1-6.el8.x86_64
dependency: info
provider: info-6.5-6.el8.x86_64
dependency: libc.so.6(GLIBC_2.15)(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: libdl.so.2()(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: libdl.so.2(GLIBC_2.2.5)(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: libgdbm.so.6()(64bit)
provider: gdbm-libs-1:1.18-1.el8.x86_64
dependency: libm.so.6()(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: libm.so.6(GLIBC_2.2.5)(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: libm.so.6(GLIBC_2.23)(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: libncursesw.so.6()(64bit)
provider: ncurses-libs-6.1-7.20180224.el8.x86_64
dependency: libpcre.so.1()(64bit)
provider: pcre-8.42-4.el8.x86_64
dependency: librt.so.1()(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: librt.so.1(GLIBC_2.2.5)(64bit)
provider: glibc-2.28-127.el8.x86_64
dependency: libtinfo.so.6()(64bit)
provider: ncurses-libs-6.1-7.20180224.el8.x86_64
dependency: rtld(GNU_HASH)
provider: glibc-2.28-127.el8.i686
provider: glibc-2.28-127.el8.x86_64
#
As you can see from the output, there are lots of different packages that must be installed for the Z shell to work properly. Good thing dnf
ensured they were all installed for us!
Just like the apt
systems, dnf
has its software repositories set up at installation. For most purposes, these preinstalled repositories will work just fine for your needs. But if and when the time comes that you need to install software from a different repository, here are some things you will need to know.
To see what repositories you are currently pulling software from, use the repolist
option.
# dnf repolist
repo id repo name
appstream CentOS Linux 8 - AppStream
baseos CentOS Linux 8 - BaseOS
extras CentOS Linux 8 - Extras
#
If you don't find a repository you need software from, then you will need to do a little configuration file editing. There are two places where the dnf
repository definitions can be located.
/etc/dnf/dnf.conf
configuration file/etc/yum.repos.d
directoryGood repository sites such as rpmfusion.org will lay out all the steps necessary to use them. Sometimes these repository sites will offer an RPM file that you can download and install. The installation of the RPM file will do all the repository setup work for you!
There may be some environments where your Linux server won't have Internet access to contact the repository to automatically download packages. For example, often high‐security environments block all network traffic except internal traffic. In these environments, you'll need a way to manually install or update software packages.
The main tool for working with .rpm
files is the rpm
program. The rpm
utility is a command‐line program to install, modify, and remove .rpm
software packages. Its basic format is as follows:
rpm action [OPTION] package
Table 5.1 describes the actions for the rpm
command.
TABLE 5.1: The rpm
Command Actions
SHORT | LONG | DESCRIPTION |
---|---|---|
‐e |
‐‐erase |
Removes the specified package |
‐F |
‐‐freshen |
Upgrades a package only if an earlier version already exists |
‐i |
‐‐install |
Installs the specified package |
‐q |
‐‐query |
Queries if the specified package is installed |
‐U |
‐‐upgrade |
Installs or upgrades the specified package |
‐V |
‐‐verify |
Verifies if the package files are present and the package's integrity |
The following sections show how to use the rpm
command to manually manage software packages.
If you need to obtain copies of RPM files on a Red Hat–based distro, such as CentOS or Fedora, you have a few different options. If you have a separate Linux system connected to the Internet, use the yumdownloader
utility. This downloads a specified rpm package file directly from the repository. The yumdownloader
tool is part of the yum‐utils
package, which you'll most likely need to install first; then you can download any rpm package from the repository.
$ yumdownloader zsh
Last metadata expiration check: 0:21:30 ago on Sat 05 Dec 2020 08:49:35 AM EST.
zsh-5.5.1-6.el8_1.2.x86_64.rpm 1.1 MB/s | 2.9 MB 00:02
$ ls -l zsh*
-rw-r--r--. 1 root root 3039264 Dec 5 09:11 zsh-5.5.1-6.el8_1.2.x86_64.rpm
$
The other method for obtaining rpm package files is using the distribution website. Most Linux distributions provide direct access to RPM files used in the distribution via a download site. For CentOS, click the RPMs
link on the Download page (mirror.centos.org/centos/8
/
at the time of this writing), next to the distribution version you have installed on the server. This takes you to a repository of all the current rpm packages for that distribution.
Use the ‐q
action to perform a simple query on the package management database for installed packages.
$ rpm -q bash
bash-4.4.19-12.el8.x86_64
$ rpm -q zsh
package zsh is not installed
$
There are several options you can add to the query action to obtain more detailed information. Table 5.2 shows a few of the more commonly used query options.
TABLE 5.2: The rpm
Command Query Action Options
SHORT OPTION | LONG OPTION | DESCRIPTION |
---|---|---|
‐c |
‐‐configfiles |
Lists the names and absolute directory references of package configuration files |
‐i |
‐‐info |
Provides detailed information, including version, installation date, and signatures |
N/A | ‐‐provides |
Shows what facilities the package provides |
‐R |
‐‐requires |
Displays various package requirements (dependencies) |
‐s |
‐‐state |
Provides states of the different files in a package, such as normal (installed), not installed , or replaced |
N/A | ‐‐what‐provides |
Shows to what package a file belongs |
You can also add the ‐i
action, which provides a detailed list of information on the package.
$ rpm -qi bash
Name : bash
Version : 4.4.19
Release : 12.el8
Architecture: x86_64
Install Date: Sat 05 Dec 2020 08:43:49 AM EST
Group : Unspecified
Size : 6861588
License : GPLv3+
Signature : RSA/SHA256, Tue 21 Jul 2020 12:08:45 PM EDT, Key ID 05b555b38483c65d
Source RPM : bash-4.4.19-12.el8.src.rpm
Build Date : Tue 21 Jul 2020 12:03:55 PM EDT
Build Host : x86-02.mbox.centos.org
Relocations : (not relocatable)
Packager : CentOS Buildsys <bugs@centos.org>
Vendor : CentOS
URL : https://www.gnu.org/software/bash
Summary : The GNU Bourne Again shell
Description :
The GNU Bourne Again shell (Bash) is a shell or command language
interpreter that is compatible with the Bourne shell (sh). Bash
incorporates useful features from the Korn shell (ksh) and the C shell
(csh). Most sh scripts can be run by bash without modification.
$
From the output of the detailed query, you can see specific information, such as the date the package was installed and a brief description of the package.
There are a couple of ways to install an rpm package that you have downloaded. For a new package, use the ‐i
action to install the package. However, if an older version of the package already exists on your system, you'll receive an error message.
It's more common to use the ‐U
action, which installs the new package, or upgrades the package if it's already installed on the system. It has also become somewhat common to add the
‐vh
options as well. The ‐h
option shows the progress of the update, and the ‐v
option shows what it's doing.
rpm -Uvh package
It's also important to remember that you must have root privileges to manually install packages, either as the root user or as a user account with root privileges.
Even though you installed the zsh package using the rpm
command‐line tool, it appears when you use the dnf
command to list the installed packages. This shows that both commands install packages to the same package management database.
To remove an installed package, just use the ‐e
action for the rpm
command.
# rpm -e zsh
# rpm -q zsh
package zsh is not installed
# dnf list installed zsh
Error: No matching Packages to list
#
The ‐e
action doesn't show if it was successful, but it will display an error message if something goes wrong with the removal. You can check to make sure the removal was successful by using the ‐q
action to query the package database or by using the dnf list installed
command.
As discussed in Chapter 3, “Installing and Maintaining Software in Ubuntu,” containers are software packaging systems that bundle all the files required to run an application into a single package. While this creates duplication of files, it helps eliminate the issue of conflicting library files and makes it easier to move application containers around between servers.
The flatpak application container format was created as an independent open source project with no direct ties to any specific Linux distribution. That said, battle lines have already been drawn, with Red Hat, CentOS, and Fedora oriented toward using flatpak instead of Canonical's snap container format.
While CentOS desktop distributions install flatpak by default, the CentOS server environment doesn't. However, you can easily install flatpak as a package using the standard dnf
or rpm
methods.
To find an application in the flatpak repository, you use the flatpak search
command.
# flatpak search mosh
Name Description Application ID Version Branch Remotes
Mosh The Mobile Shell org.mosh.mosh 1.3.2 stable flathub
#
When working with a container, you must use its Application ID value and not its name. To install the application, use the flatpak install
command.
# flatpak install org.mosh.mosh
Looking for matches…
Found similar ref(s) for 'mosh' in remote 'flathub' (system).
Use this remote? [Y/n]: y
Found ref 'app/org.mosh.mosh/x86_64/stable' in remote 'flathub' (system).
Use this ref? [Y/n]: y
Required runtime for org.mosh.mosh/x86_64/stable (runtime/org.freedesktop.Platform/x86_64/20.08) found in remote flathub
Do you want to install it? [Y/n]: y
…
Installation complete.
#
To check whether the installation went well, you can use the flatpak list
command again.
# flatpak list
Name Application ID Version Branch Installation
Freedesktop Plat… org.freedesktop.Platform 20.08.2 20.08 system
default …freedesktop.Platform.GL.default 20.08 system
openh264 …g.freedesktop.Platform.openh264 2.1.0 2.0 system
Mosh org.mosh.mosh 1.3.2 stable system
#
Finally, to remove an application container, use the flatpak uninstall
command.
# flatpak uninstall org.mosh.mosh
ID Branch Op
1. [-] org.mosh.mosh stable r
Uninstall complete.
#
Using application containers is similar to using package management systems, but what goes on behind the scenes is fundamentally different. However, the end result is that you have an application installed on your Linux system that can be easily maintained and upgraded.
rpm
command‐line tool provides access to the package management database, allowing you to quickly determine the status of installed packages.
dnf
for installing and managing software packages. The dnf
tool automatically installs any software packages required by the package you install.
rpm
command to manually install the package. The most common options used to install software are the ‐Uvh
options, which will update the package if it's already installed and provide verbose information on the installation progress.