How to install and update software packages using the yum command

Managing Software Packages with YUM

The low-level rpm command can be used to install packages, but it is not designed to work with package repositories or resolve dependencies from multiple sources automatically.

Yum is designed to be a better system for managing RPM-based software installation and updates. The yum command allows you to install, update, remove, and get information about software packages and their dependencies. You can get a history of transactions performed and work with multiple Red Hat and third-party software repositories.

Finding Software with Yum

1. yum help displays usage information.

2. yum list displays installed and available packages.

[user@host ~]$ yum list 'http*'
Available Packages
http-parser.i686              2.8.0-2.el8                        rhel8-appstream
http-parser.x86_64            2.8.0-2.el8                        rhel8-appstream
httpcomponents-client.noarch  4.5.5-4.module+el8+2452+b359bfcd   rhel8-appstream
httpcomponents-core.noarch    4.4.10-3.module+el8+2452+b359bfcd  rhel8-appstream
httpd.x86_64                  2.4.37-7.module+el8+2443+605475b7  rhel8-appstream
httpd-devel.x86_64            2.4.37-7.module+el8+2443+605475b7  rhel8-appstream
httpd-filesystem.noarch       2.4.37-7.module+el8+2443+605475b7  rhel8-appstream
httpd-manual.noarch           2.4.37-7.module+el8+2443+605475b7  rhel8-appstream
httpd-tools.x86_64            2.4.37-7.module+el8+2443+605475b7  rhel8-appstream

3. yum search KEYWORD lists packages by keywords found in the name and summary fields only. To search for packages that have “web server” in their name, summary, and description fields, use search all:

[user@host ~]$ yum search all 'web server'
================= Summary & Description Matched: web server ====================
pcp-pmda-weblog.x86_64 : Performance Co-Pilot (PCP) metrics from web server logs
nginx.x86_64 : A high performance web server and reverse proxy server
======================== Summary Matched: web server ===========================
libcurl.x86_64 : A library for getting files from web servers
libcurl.i686 : A library for getting files from web servers
libcurl.x86_64 : A library for getting files from web servers
====================== Description Matched: web server =========================
httpd.x86_64 : Apache HTTP Server
git-instaweb.x86_64 : Repository browser in gitweb
...output omitted...

4. yum info PACKAGENAME returns detailed information about a package, including the disk space needed for installation. To get information on the Apache HTTP Server:

[user@host ~]$ yum info httpd
Available Packages
Name         : httpd
Version      : 2.4.37
Release      : 7.module+el8+2443+605475b7
Arch         : x86_64
Size         : 1.4 M
Source       : httpd-2.4.37-7.module+el8+2443+605475b7.src.rpm
Repo         : rhel8-appstream
Summary      : Apache HTTP Server
URL          : https://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, efficient, and extensible
             : web server.

5. yum provides PATHNAME displays packages that match the path name specified (which often include wildcard characters). To find packages that provide the /var/www/html directory, use:

[user@host ~]$ yum provides /var/www/html
httpd-filesystem-2.4.37-7.module+el8+2443+605475b7.noarch : The basic directory
layout for the Apache HTTP server
Repo        : rhel8-appstream
Matched from: Filename    : /var/www/html

Installing and removing software with yum

1. yum install PACKAGENAME obtains and installs a software package, including any dependencies.


[user@host ~]$ yum install httpd
Dependencies resolved.
================================================================================
  Package                  Arch       Version             Repository        Size
================================================================================
Installing:
  httpd                    x86_64     2.4.37-7.module...  rhel8-appstream   1.4 M
Installing dependencies:
  apr                      x86_64     1.6.3-8.el8         rhel8-appstream   125 k
  apr-util                 x86_64     1.6.1-6.el8         rhel8-appstream   105 k
...output omitted...
Transaction Summary
================================================================================
Install  9 Packages

Total download size: 2.0 M
Installed size: 5.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/9): apr-util-bdb-1.6.1-6.el8.x86_64.rpm           464 kB/s |  25 kB     00:00
(2/9): apr-1.6.3-8.el8.x86_64.rpm                    1.9 MB/s | 125 kB     00:00
(3/9): apr-util-1.6.1-6.el8.x86_64.rpm               1.3 MB/s | 105 kB     00:00
...output omitted...
Total                                                8.6 MB/s | 2.0 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                         1/1
  Installing       : apr-1.6.3-8.el8.x86_64                                  1/9
  Running scriptlet: apr-1.6.3-8.el8.x86_64                                  1/9
  Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                         2/9
...output omitted...
Installed:
  httpd-2.4.37-7.module+el8+2443+605475b7.x86_64 apr-util-bdb-1.6.1-6.el8.x86_64
  apr-util-openssl-1.6.1-6.el8.x86_64            apr-1.6.3-8.el8.x86_64
...output omitted...
Complete!

2. yum update PACKAGENAME obtains and installs a newer version of the specified package, including any dependencies. Generally the process tries to preserve configuration files in place, but in some cases, they may be renamed if the packager thinks the old one will not work after the update. With no PACKAGENAME specified, it installs all relevant updates.

[user@host ~]$ sudo yum update

Since a new kernel can only be tested by booting to that kernel, the package is specifically designed so that multiple versions may be installed at once. If the new kernel fails to boot, the old kernel is still available. Using yum update kernel will actually install the new kernel. The configuration files hold a list of packages to always install even if the administrator requests an update.

[user@host ~]$ yum list kernel
Installed Packages
kernel.x86_64         4.18.0-60.el8         @anaconda
kernel.x86_64         4.18.0-67.el8         @rhel-8-for-x86_64-baseos-htb-rpms

[user@host ~]$ uname -r
4.18.0-60.el8.x86_64

[user@host ~]$ uname -a
Linux host.lab.example.com 4.18.0-60.el8.x86_64 #1 SMP Fri Jan 11 19:08:11 UTC
2019 x86_64 x86_64 x86_64 GNU/Linux

3. yum remove PACKAGENAME removes an installed software package, including any supported packages.

[user@host ~]$ sudo yum remove httpd

Installing and removing groups of software with yum

1. yum also has the concept of groups, which are collections of related software installed together for a particular purpose. In CentOS/RHEL 8, there are two kinds of groups. Regular groups are collections of packages. Environment groups are collections of regular groups. The packages or groups provided by a group may be mandatory (they must be installed if the group is installed), default (normally installed if the group is installed), or optional (not installed when the group is installed, unless specifically requested).

Like yum list, the yum group list command shows the names of installed and available groups.

[user@host ~]$ yum group list
Available Environment Groups:
  Server with GUI
  Minimal Install
  Server
...output omitted...
Available Groups:
  Container Management
  .NET Core Development
  RPM Development Tools
...output omitted...

Some groups are normally installed through environment groups and are hidden by default. List these hidden groups with the yum group list hidden command.

2. yum group info displays information about a group. It includes a list of mandatory, default, and optional package names.

[user@host ~]$ yum group info "RPM Development Tools"
Group: RPM Development Tools
  Description: These tools include core development tools such rpmbuild.
    Mandatory Packages:
      redhat-rpm-config
      rpm-build
    Default Packages:
      rpmdevtools
    Optional Packages:
      rpmlint

3. yum group install installs a group that installs its mandatory and default packages and the packages they depend on.

[user@host ~]$ sudo yum group install "RPM Development Tools"
...output omitted...
Installing Groups:
  RPM Development Tools

  Transaction Summary
  ===============================================================================
  Install  64 Packages

  Total download size: 21 M
  Installed size: 62 M
  Is this ok [y/N]: y
...output omitted...

Viewing transaction history

1. All install and remove transactions are logged in /var/log/dnf.rpm.log.

[user@host ~]$ tail -5 /var/log/dnf.rpm.log
2019-02-26T18:27:00Z SUBDEBUG Installed: rpm-build-4.14.2-9.el8.x86_64
2019-02-26T18:27:01Z SUBDEBUG Installed: rpm-build-4.14.2-9.el8.x86_64
2019-02-26T18:27:01Z SUBDEBUG Installed: rpmdevtools-8.10-7.el8.noarch
2019-02-26T18:27:01Z SUBDEBUG Installed: rpmdevtools-8.10-7.el8.noarch
2019-02-26T18:38:40Z INFO --- logging initialized --

2. yum history displays a summary of install and remove transactions.

[user@host ~]$ sudo yum history
ID     | Command line             | Date and time    | Action(s)      | Altered
------------------------------------------------------------------------------
     7 | group install RPM Develo | 2019-02-26 13:26 | Install        |   65
     6 | update kernel            | 2019-02-26 11:41 | Install        |    4
     5 | install httpd            | 2019-02-25 14:31 | Install        |    9
     4 | -y install @base firewal | 2019-02-04 11:27 | Install        |  127 EE
     3 | -C -y remove firewalld - | 2019-01-16 13:12 | Removed        |   11 EE
     2 | -C -y remove linux-firmw | 2019-01-16 13:12 | Removed        |    1
     1 |                          | 2019-01-16 13:05 | Install        |  447 EE

3. The history undo option reverses a transaction.

[user@host ~]$ sudo yum history undo 5
Undoing transaction 7, from Tue 26 Feb 2019 10:40:32 AM EST
Install apr-1.6.3-8.el8.x86_64                              @rhel8-appstream
Install apr-util-1.6.1-6.el8.x86_64                         @rhel8-appstream
Install apr-util-bdb-1.6.1-6.el8.x86_64                     @rhel8-appstream
Install apr-util-openssl-1.6.1-6.el8.x86_64                 @rhel8-appstream
Install httpd-2.4.37-7.module+el8+2443+605475b7.x86_64      @rhel8-appstream
...output omitted...

SUMMARY OF YUM COMMANDS

Packages can be located, installed, updated, and removed by name or by package groups.

TASK: COMMAND:
List installed and available packages by name yum list [NAME-PATTERN]
List installed and available groups yum group list
Search for a package by keyword yum search KEYWORD
Show details of a package yum info PACKAGENAME
Install a package yum install PACKAGENAME
Install a package group yum group install GROUPNAME
Update all packages yum update
Remove a package yum remove PACKAGENAME
Display transaction history yum history