YUM Package Manager

YUM (originally known as Yellowdog Updater Modified) is a command line package manager for use with rpm based Linux distributions. Yum was originally created to manage Red Hat Enterprise Linux systems, however many other popular distributions now use this tool as the command line package manager of choice. Distributions such as CentOS and Fedora use Yum. However, yum is being phased out and being replaced with the "DNF" package manager. Yum offers a simple to use interface for the updating, and removal of packages. Yum also handles all dependencies and pre-requisites.

YUM Command Examples

The most common functions used within Yum are the "install", "erase", "update", "list" and "search". However, yum has many more functions that can be carried out. Below are some of the common uses for yum:

Display YUM Version

Basic Syntax: yum --version


# yum --version
4.2.23
  Installed: dnf-0:4.2.23-4.el8.noarch at Mon 05 Apr 2021 13:25:49 GMT
  Built    : CentOS Buildsys  at Tue 04 Aug 2020 18:52:03 GMT

  Installed: rpm-0:4.14.3-4.el8.x86_64 at Mon 05 Apr 2021 13:25:13 GMT
  Built    : CentOS Buildsys  at Tue 21 Jul 2020 17:36:08 GMT

The above command is used to display the currently installed version of the yum package manager.

Yum is now a symbolic link that points to "dnf". This example was taken from a CentOS 8 system.

Displaying Repositories - yum repolist

Basic Syntax: yum repolist


# yum repolist
repo id                         repo name
appstream                       CentOS Linux 8 - AppStream
baseos                          CentOS Linux 8 - BaseOS
extras                          CentOS Linux 8 - Extras

The command "yum repolist" will display all enabled repositories. You may pass an additional parameter of "all" to display enabled and disabled repositories.


# yum repolist all
repo id          repo name                                              status
appstream        CentOS Linux 8 - AppStream                             enabled
appstream-source CentOS Linux 8 - AppStream - Source                    disabled
baseos           CentOS Linux 8 - BaseOS                                enabled
baseos-source    CentOS Linux 8 - BaseOS - Source                       disabled
cr               CentOS Linux 8 - ContinuousRelease                     disabled
debuginfo        CentOS Linux 8 - Debuginfo                             disabled
devel            CentOS Linux 8 - Devel WARNING! FOR BUILDROOT USE ONLY disabled
extras           CentOS Linux 8 - Extras                                enabled
extras-source    CentOS Linux 8 - Extras - Source                       disabled
fasttrack        CentOS Linux 8 - FastTrack                             disabled
ha               CentOS Linux 8 - HighAvailability                      disabled
media-appstream  CentOS Linux 8 - Media - AppStream                     disabled
media-baseos     CentOS Linux 8 - Media - BaseOS                        disabled
plus             CentOS Linux 8 - Plus                                  disabled
plus-source      CentOS Linux 8 - Plus - Source                         disabled
powertools       CentOS Linux 8 - PowerTools                            disabled

Yum installing a package

Basic Syntax: yum install package-name


# yum install nmap
Last metadata expiration check: 0:05:32 ago on Thu 06 May 2021 19:08:16 BST.
Dependencies resolved.
================================================================================
 Package           Architecture   Version               Repository         Size
================================================================================
Installing:
 nmap              x86_64         2:7.70-5.el8          appstream         5.8 M
Installing dependencies:
 nmap-ncat         x86_64         2:7.70-5.el8          appstream         237 k

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 6.1 M
Installed size: 25 M
Is this ok [y/N]: y

If the package is available within our repositories, then we are prompted to reply "y/N" to confirm our actions. In this case we are going to reply "y" to install the package called "nmap" and any dependencies.


Downloading Packages:
(1/2): nmap-ncat-7.70-5.el8.x86_64.rpm          1.3 MB/s | 237 kB     00:00    
(2/2): nmap-7.70-5.el8.x86_64.rpm               4.9 MB/s | 5.8 MB     00:01    
--------------------------------------------------------------------------------
Total                                           4.0 MB/s | 6.1 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : nmap-ncat-2:7.70-5.el8.x86_64                          1/2 
  Running scriptlet: nmap-ncat-2:7.70-5.el8.x86_64                          1/2 
  Installing       : nmap-2:7.70-5.el8.x86_64                               2/2 
  Running scriptlet: nmap-2:7.70-5.el8.x86_64                               2/2 
  Verifying        : nmap-2:7.70-5.el8.x86_64                               1/2 
  Verifying        : nmap-ncat-2:7.70-5.el8.x86_64                          2/2 

Installed:
  nmap-2:7.70-5.el8.x86_64             nmap-ncat-2:7.70-5.el8.x86_64            

Complete!

As you can see from the above, the requested package has been installed successfully.

Yum Removing a package

Basic Syntax: yum erase package-name or yum remove package-name


# yum remove nmap
Dependencies resolved.
================================================================================
 Package           Architecture   Version              Repository          Size
================================================================================
Removing:
 nmap              x86_64         2:7.70-5.el8         @appstream          24 M
Removing unused dependencies:
 nmap-ncat         x86_64         2:7.70-5.el8         @appstream         681 k

Transaction Summary
================================================================================
Remove  2 Packages

Freed space: 25 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Erasing          : nmap-2:7.70-5.el8.x86_64                               1/2 
  Erasing          : nmap-ncat-2:7.70-5.el8.x86_64                          2/2 
  Running scriptlet: nmap-ncat-2:7.70-5.el8.x86_64                          2/2 
  Verifying        : nmap-2:7.70-5.el8.x86_64                               1/2 
  Verifying        : nmap-ncat-2:7.70-5.el8.x86_64                          2/2 

Removed:
  nmap-2:7.70-5.el8.x86_64             nmap-ncat-2:7.70-5.el8.x86_64            

Complete!

In this example we removed the package "nmap" with the command "yum remove nmap". You can also use the "erase" option to achieve the same result.

Listing Installed Packages

Basic Syntax: yum list installed


# yum list installed
Installed Packages
NetworkManager.x86_64                1:1.26.0-12.el8_3                @baseos   
NetworkManager-libnm.x86_64          1:1.26.0-12.el8_3                @baseos   
NetworkManager-team.x86_64           1:1.26.0-12.el8_3                @baseos   
NetworkManager-tui.x86_64            1:1.26.0-12.el8_3                @baseos   
acl.x86_64                           2.2.53-1.el8                     @anaconda 
adcli.x86_64                         0.8.2-7.el8                      @anaconda 
at.x86_64                            3.1.20-11.el8                    @anaconda 
attr.x86_64                          2.4.48-3.el8                     @anaconda 
audit.x86_64                         3.0-0.17.20191104git1c2f876.el8  @anaconda 
audit-libs.x86_64                    3.0-0.17.20191104git1c2f876.el8  @anaconda 
authselect.x86_64                    1.2.1-2.el8                      @anaconda 

In the above example we issued the "yum list installed" command. This command will display any packages that have been installed on your Linux system. However, the output returned will be considerable in size. Above is a small section from the output of this command.

If you know the name of the package you want to check, you can specify this using the syntax: "yum list installed package-name". For example, if we wanted to check for a package called "bzip2", we would issue the following command

yum list installed bzip2


# yum list installed bzip2
Installed Packages
bzip2.x86_64                       1.0.6-26.el8                        @anaconda

Display package information

To display information about a package, the "info" parameter can be passed. As an example, if we wanted to know more information about the package "bzip2", we would issue the following command:

yum info bzip2


# yum info bzip2
Last metadata expiration check: 0:24:10 ago on Thu 06 May 2021 19:08:16 BST.
Installed Packages
Name         : bzip2
Version      : 1.0.6
Release      : 26.el8
Architecture : x86_64
Size         : 91 k
Source       : bzip2-1.0.6-26.el8.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : A file compression utility
URL          : http://www.bzip.org/
License      : BSD
Description  : Bzip2 is a freely available, patent-free, high quality data
             : compressor. Bzip2 compresses files to within 10 to 15 percent of
             : the capabilities of the best techniques available.  However,
             : bzip2 has the added benefit of being approximately two times
             : faster at compression and six times faster at decompression than
             : those techniques.  Bzip2 is not the fastest compression utility,
             : but it does strike a balance between speed and compression
             : capability.
             : 
             : Install bzip2 if you need a compression utility.

From the above,we can see that the package "bzip2" is listed as an "Installed Package".

Checking for Updates

Basic Syntax: yum check-update

The "yum check-update" command can be run to check for any updates to packages on your system. Any updates that are available will then be displayed. You may also use the command "yum list updates". Any updates that are available to your system will be displayed.

Check for updates for specific package

Basic Syntax: yum list package


# yum list openssl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.vooservers.com
 * epel: mirrors.ukfast.co.uk
 * extras: repo.bigstepcloud.com
 * updates: mirror.ukhost4u.com
Installed Packages
openssl.x86_64    1.0.1e-42.el6         @anaconda-CentOS-201508042137.x86_64/6.7
Available Packages
openssl.i686      1.0.1e-42.el6_7.2     updates                                 
openssl.x86_64    1.0.1e-42.el6_7.2     updates  

In the above example we were checking for any available updates for the package called "openssl". The relevant information is displayed under the headings "Available Packages" and "Available Packages". In the above example we can see that a newer version of the openssl package is available. To update the package, you would issue the command: "yum update openssl".

Update all Installed Packages

Basic Syntax: yum update


# yum update
Last metadata expiration check: 0:58:44 ago on Thu 06 May 2021 19:08:16 BST.
Dependencies resolved.
Nothing to do.
Complete!

In the above example we are installing any updates that are available for any installed packages on our system. In the above example, no updates were found as the system is upto-date. If packages are available, they will be displayed as number of packages to be installed along with the number of packages to be upgraded.

Search for a package

To search for a package, the command "yum search pattern can be used. Any packages that match the pattern will be displayed.

Basic Syntax: yum search pattern


# yum search bash
Last metadata expiration check: 1:02:22 ago on Thu 06 May 2021 19:08:16 BST.
========================== Name Exactly Matched: bash ==========================
bash.x86_64 : The GNU Bourne Again shell
========================= Name & Summary Matched: bash =========================
bash-completion.noarch : Programmable completion for Bash
bash-doc.x86_64 : Documentation files for bash
libguestfs-bash-completion.noarch : Bash tab-completion scripts for libguestfs
                                  : tools
libvirt-bash-completion.x86_64 : Bash completion script
nbdkit-bash-completion.noarch : Bash tab-completion for nbdkit
pcp-pmda-bash.x86_64 : Performance Co-Pilot (PCP) metrics for the Bash shell
============================ Summary Matched: bash =============================
python3-argcomplete.noarch : Bash tab completion for argparse

In the above example we searched for any packages that contained the string "bash". This option is useful if you do not know the full name of a package.

yum provides

Basic Syntax: yum provides package-file>

The above command displays which package provides the specified file. As an example, If you wanted to find which package provides the utility "netstat, then you would issue the following command:
"yum provides netstat"


# yum provides netstat
Last metadata expiration check: 1:08:39 ago on Thu 06 May 2021 19:08:16 BST.
net-tools-2.0-0.52.20160912git.el8.x86_64 : Basic networking tools
Repo        : baseos
Matched from:
Filename    : /usr/bin/netstat

# yum install net-tools
Last metadata expiration check: 1:08:54 ago on Thu 06 May 2021 19:08:16 BST.
Dependencies resolved.
================================================================================
 Package         Architecture Version                        Repository    Size
================================================================================
Installing:
 net-tools       x86_64       2.0-0.52.20160912git.el8       baseos       322 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 322 k
Installed size: 942 k
Is this ok [y/N]: y
Downloading Packages:
net-tools-2.0-0.52.20160912git.el8.x86_64.rpm   1.8 MB/s | 322 kB     00:00    
--------------------------------------------------------------------------------
Total                                           524 kB/s | 322 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : net-tools-2.0-0.52.20160912git.el8.x86_64              1/1 
  Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64              1/1 
  Verifying        : net-tools-2.0-0.52.20160912git.el8.x86_64              1/1 

Installed:
  net-tools-2.0-0.52.20160912git.el8.x86_64                                     

Complete!

In the above example, we used the "yum provides" command to identify the package that would install the "netstat" utility. Once the package was identified, we then installed the package making "netstat" available.

Reinstalling a Package

Basic Syntax: yum reinstall package name

The "yum reinstall" command is used to reinstall the specified package.


# yum reinstall net-tools
Last metadata expiration check: 1:13:20 ago on Thu 06 May 2021 19:08:16 BST.
Dependencies resolved.
================================================================================
 Package         Architecture Version                        Repository    Size
================================================================================
Reinstalling:
 net-tools       x86_64       2.0-0.52.20160912git.el8       baseos       322 k

Transaction Summary
================================================================================

Total download size: 322 k
Installed size: 942 k
Is this ok [y/N]: y
Downloading Packages:
net-tools-2.0-0.52.20160912git.el8.x86_64.rpm   1.3 MB/s | 322 kB     00:00    
--------------------------------------------------------------------------------
Total                                           853 kB/s | 322 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64              1/1 
  Reinstalling     : net-tools-2.0-0.52.20160912git.el8.x86_64              1/2 
  Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64              1/2 
  Cleanup          : net-tools-2.0-0.52.20160912git.el8.x86_64              2/2 
  Running scriptlet: net-tools-2.0-0.52.20160912git.el8.x86_64              2/2 
  Verifying        : net-tools-2.0-0.52.20160912git.el8.x86_64              1/2 
  Verifying        : net-tools-2.0-0.52.20160912git.el8.x86_64              2/2 

Reinstalled:
  net-tools-2.0-0.52.20160912git.el8.x86_64                                     

Complete!

Downgrading a Package

Basic Syntax: yum downgrade package-name

The "yum downgrade" command is used to downgrade the specified packages to the highest of all known lower versions if possible. To establish the current version of a package you can use the command "yum list package-name".

Be very careful when downgrading packages as they can impact the stability of your system. Always check the output first to see exactly what is going to be downgraded. You should never attempt to rollback the following packages: "dbus, kernel, glibc and selinux-policy".

Example:


# yum list openssl.x86_64
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.vooservers.com
 * epel: mirrors.ukfast.co.uk
 * extras: repo.bigstepcloud.com
 * updates: mirror.ukhost4u.com
Installed Packages
openssl.x86_64                    1.0.1e-42.el6_7.2                     @updates

# yum downgrade openssl.x86_64
Loaded plugins: fastestmirror
Setting up Downgrade Process
Loading mirror speeds from cached hostfile
 * base: mirrors.vooservers.com
 * epel: mirrors.ukfast.co.uk
 * extras: repo.bigstepcloud.com
 * updates: mirror.ukhost4u.com
Resolving Dependencies
--> Running transaction check
---> Package openssl.x86_64 0:1.0.1e-42.el6_7.1 will be a downgrade
---> Package openssl.x86_64 0:1.0.1e-42.el6_7.2 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package         Arch           Version                   Repository       Size
================================================================================
Downgrading:
 openssl         x86_64         1.0.1e-42.el6_7.1         updates         1.5 M

Transaction Summary
================================================================================
Downgrade     1 Package(s)

Total download size: 1.5 M
Is this ok [y/N]: y
Downloading Packages:
openssl-1.0.1e-42.el6_7.1.x86_64.rpm                     | 1.5 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : openssl-1.0.1e-42.el6_7.1.x86_64                             1/2 
  Cleanup    : openssl-1.0.1e-42.el6_7.2.x86_64                             2/2 
  Verifying  : openssl-1.0.1e-42.el6_7.1.x86_64                             1/2 
  Verifying  : openssl-1.0.1e-42.el6_7.2.x86_64                             2/2 

Removed:
  openssl.x86_64 0:1.0.1e-42.el6_7.2                                            

Installed:
  openssl.x86_64 0:1.0.1e-42.el6_7.1                                            

Complete!

List available groups

Many packages on Linux systems are bundled together as a group of packages. So instead of installing a list of individual packages, you can specify a group of packages to install.

Below is a list of available groups on a standard CentOS 8 installation. These groups can be displayed by issuing the following command":

yum grouplist


# yum grouplist
Last metadata expiration check: 1:28:25 ago on Thu 06 May 2021 19:08:16 BST.
Available Environment Groups:
   Server with GUI
   Server
   Workstation
   Virtualization Host
   Custom Operating System
Installed Environment Groups:
   Minimal Install
Available Groups:
   Container Management
   .NET Core Development
   RPM Development Tools
   Development Tools
   Graphical Administration Tools
   Headless Management
   Legacy UNIX Compatibility
   Network Servers
   Scientific Support
   Security Tools
   Smart Card Support
   System Tools

If we wanted to install a Graphical desktop, we could issue the command: yum group install "Server with GUI". Notice, you have to include double quotes around the group name if there are spaces within the name of the group.

Below is a small extract of the typical output you would see from this command:


Installing Environment Groups:
 Server with GUI                                                               
Installing Groups:
 base-x                                                                        
 Container Management                                                          
 Core                                                                          
 Fonts                                                                         
 GNOME                                                                         
 Guest Desktop Agents                                                          
 Hardware Monitoring Utilities                                                 
 Hardware Support                                                              
 Headless Management                                                           
 Input Methods                                                                 
 Internet Browser                                                              
 Multimedia                                                                    
 Common NetworkManager submodules
                                                                               
 Printing Client                                                               
 Server product core                                                           
 Standard                                                                      

Transaction Summary
================================================================================
Install  879 Packages

Total download size: 833 M
Installed size: 2.3 G
Is this ok [y/N]: 

If you did want to install the Graphical interface for your server, you would also need to change the default target level by issuing the following command:
systemctl set-default graphical

The above command instructs your system to boot into graphical mode.

Remove a group package

The command used to remove a group package is: yum groupremove "group package name"

Display Transaction History

Basic Syntax: yum history

The "yum history" command is used to display transactions that have happened in the past. This command enables you to view the last updates or packages that have been installed to your system.


# yum history
ID     | Command line              | Date and time    | Action(s)      | Altered
--------------------------------------------------------------------------------
    11 | reinstall net-tools       | 2021-05-06 20:21 | R              |    2   
    10 | install net-tools         | 2021-05-06 20:17 | Install        |    1   
     9 | remove net-tools          | 2021-05-06 20:16 | Removed        |    1   
     8 | remove nmap               | 2021-05-06 19:21 | Removed        |    2   
     7 | install nmap              | 2021-05-06 19:16 | Install        |    2   
     6 | update                    | 2021-05-06 19:12 | Upgrade        |    2   
     5 | install pcp-system-tools  | 2021-04-25 11:11 | Install        |   16   
     4 | update                    | 2021-04-25 11:05 | I, U           |   77 EE
     3 | install iptraf-ng         | 2021-04-24 19:32 | Install        |    1   
     2 | install wget              | 2021-04-24 13:48 | Install        |    1   
     1 |                           | 2021-04-05 14:23 | Install        |  447 EE

The above output identifies what packages were installed along with a date and time. For a full list of all packages, we need to use the command "yum history info ID" command

Yum History Info

To view the history of any transaction, issue the command: "yum history info ID". Replace the "ID" with the number displayed in the ID column.


# yum history info 6
Transaction ID : 6
Begin time     : Thu 06 May 2021 19:12:51 BST
Begin rpmdb    : 470:d7376df017ace90b964fedfacdeb043a79bd3363
End time       : Thu 06 May 2021 19:13:34 BST (43 seconds)
End rpmdb      : 470:90a69471d69beece85331af7c03515de544d9166
User           : John 
Return-Code    : Success
Releasever     : 8
Command Line   : update
Comment        : 
Packages Altered:
    Upgrade  selinux-policy-3.14.3-54.el8_3.4.noarch          @baseos
    Upgraded selinux-policy-3.14.3-54.el8_3.2.noarch          @@System
    Upgrade  selinux-policy-targeted-3.14.3-54.el8_3.4.noarch @baseos
    Upgraded selinux-policy-targeted-3.14.3-54.el8_3.2.noarch @@System


From the above, we can see that two packages were upgraded.

Help with yum

For a full list of all available commands and options, issue the command: "yum --help".