25 Useful yum Command Examples For Package Management In Linux

Yellowdog Updater Modifier (yum) is an RPM based package manager which is used to install and update packages in various Linux distributions including CentOS, RHEL and Fedora.

Yum is quite powerful as it’s capable of automatically resolving dependency issues, and is similar to other package managers such as ‘apt-get’ in Debian based distributions.

These examples should serve as a useful introduction, guide or cheat sheet style resource for how to use the yum command in Linux.

How To Use yum – Command Examples

  • 1. Install New Package From Repository

    The yum command can be used to install packages from a repository with the ‘install’ argument, followed by the package name. In the example below, we are installing Apache, which is provided in the ‘httpd’ package.

    [root@centos7 ~]# yum install httpd
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ========================================================================
     Package        Arch        Version                   Repository    Size
    ========================================================================
    Installing:
     httpd          x86_64      2.4.6-40.el7.centos.4     updates      2.7 M
    
    Transaction Summary
    ========================================================================
    Install  1 Package
    
    Total download size: 2.7 M
    Installed size: 9.4 M
    Is this ok [y/d/N]: y
    Downloading packages:
    httpd-2.4.6-40.el7.centos.4.x86_64.rpm        | 2.7 MB  00:00:00
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : httpd-2.4.6-40.el7.centos.4.x86_64            1/1
      Verifying  : httpd-2.4.6-40.el7.centos.4.x86_64            1/1
    
    Installed:
      httpd.x86_64 0:2.4.6-40.el7.centos.4
    
    Complete!
    

    Note that after confirming the packages that will be installed, you will be asked to provide input. In this case we entered ‘y’ for yes to proceed with the installation, which then completed successfully.

  • 2. Assume Yes

    In the first example we were prompted to press the ‘y’ key in order to proceed with the installation. Rather than being prompted each time for user input, we can simply specify the ‘-y’ option in our command for assume yes. This way we will not be prompted for any input and yum will assume that everything will be answered with yes.

    [root@centos7 ~]# yum install httpd-manual -y
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd-manual.noarch 0:2.4.6-40.el7.centos.4 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==========================================================================
     Package              Arch      Version                  Repository   Size
    ==========================================================================
    Installing:
     httpd-manual         noarch    2.4.6-40.el7.centos.4    updates     1.3 M
    
    Transaction Summary
    ==========================================================================
    Install  1 Package
    
    Total download size: 1.3 M
    Installed size: 5.5 M
    Downloading packages:
    httpd-manual-2.4.6-40.el7.centos.4.noarch.rpm      | 1.3 MB  00:00:01
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : httpd-manual-2.4.6-40.el7.centos.4.noarch        1/1
      Verifying  : httpd-manual-2.4.6-40.el7.centos.4.noarch        1/1
    
    Installed:
      httpd-manual.noarch 0:2.4.6-40.el7.centos.4
    
    Complete!
    

    Note that in this example we were not prompted for input, as assume yes has been provided, so the package was installed fully without any further user interaction.

  • 3. Check For Available Updates

    We can run yum with the ‘check-update’ argument which will check in with our enabled repositories for any updates that may be available for packages that we have installed. This does not actually perform any updates, it simply gives us a list of packages that have updates available for installation.

    [root@centos7 ~]# yum check-update
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    
    bash.x86_64                             4.2.46-20.el7_2        updates
    dbus.x86_64                             1:1.6.12-14.el7_2      updates
    dbus-libs.x86_64                        1:1.6.12-14.el7_2      updates
    device-mapper-persistent-data.x86_64    0.6.2-1.el7_2          updates
    glibc.x86_64                            2.17-106.el7_2.8       updates
    glibc-common.x86_64                     2.17-106.el7_2.8       updates
    initscripts.x86_64                      9.49.30-1.el7_2.3      updates
    kernel.x86_64                           3.10.0-327.28.3.el7    updates
    kernel-tools.x86_64                     3.10.0-327.28.3.el7    updates
    kernel-tools-libs.x86_64                3.10.0-327.28.3.el7    updates
    ...
    
  • 4. Update New Package From Repository

    In the previous example we have been provided with a list of packages that currently have package updates available. We can perform an update to a specific package by specifying it after the ‘update’ argument, as shown below.

    [root@centos7 ~]# yum update bash -y
    Resolving Dependencies
    --> Running transaction check
    ---> Package bash.x86_64 0:4.2.46-19.el7 will be updated
    ---> Package bash.x86_64 0:4.2.46-20.el7_2 will be an update
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =================================================================
     Package         Arch       Version             Repository   Size
    =================================================================
    Updating:
     bash            x86_64     4.2.46-20.el7_2     updates     1.0 M
    
    Transaction Summary
    =================================================================
    Upgrade  1 Package
    
    Total download size: 1.0 M
    Downloading packages:
    Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
    bash-4.2.46-20.el7_2.x86_64.rpm        | 1.0 MB  00:00:00
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Updating   : bash-4.2.46-20.el7_2.x86_64            1/2
      Cleanup    : bash-4.2.46-19.el7.x86_64              2/2
      Verifying  : bash-4.2.46-20.el7_2.x86_64            1/2
      Verifying  : bash-4.2.46-19.el7.x86_64              2/2
    
    Updated:
      bash.x86_64 0:4.2.46-20.el7_2
    
    Complete!
    

    Note that we do not have to run check-update prior to this.

    While we can update specified packages in this manner, it is often easier to simply apply all available updates for all packages on the system with ‘yum update’.

  • 5. Download Package RPM File

    Rather than installing a package from the repository as demonstrated previously, we can optionally download the .rpm file from the repository with the ‘yumdownloader’ command.

    The ‘yumdownloader’ command comes from the ‘yum-utils’ package, so we install this first.

    [root@centos7 ~]# yum install yum-utils -y
    

    Now we can download the RPM file to the local system.

    [root@centos7 ~]# yumdownloader unbound
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror.ventraip.net.au
     * extras: mirror.optus.net
     * updates: mirror.optus.net
    unbound-1.4.20-26.el7.x86_64.rpm
    [root@centos7 ~]# ls -la unbound-1.4.20-26.el7.x86_64.rpm
    -rw-r--r--. 1 root root 483136 Nov 26  2015 unbound-1.4.20-26.el7.x86_64.rpm
    
  • 6. Perform Local Install Of RPM File

    In this example we will install the .rpm file that we just downloaded with ‘yumdownloader’. While we could have just installed this package from the repository directly with ‘yum install’, sometimes you may be provided with .rpm files directly for installation so it’s worth knowing how to install them.

    While .rpm files can be installed with the ‘rpm’ command, using yum has the advantage of automatically detecting and installing any other package dependencies that may also be required.

    [root@centos7 ~]# yum localinstall unbound-1.4.20-26.el7.x86_64.rpm
    Loaded plugins: fastestmirror
    Examining unbound-1.4.20-26.el7.x86_64.rpm: unbound-1.4.20-26.el7.x86_64
    Marking unbound-1.4.20-26.el7.x86_64.rpm to be installed
    Resolving Dependencies
    --> Running transaction check
    ---> Package unbound.x86_64 0:1.4.20-26.el7 will be installed
    --> Processing Dependency: unbound-libs(x86-64) = 1.4.20-26.el7 for package: unbound-1.4.20-26.el7.x86_64
    Loading mirror speeds from cached hostfile
     * base: mirror.ventraip.net.au
     * extras: mirror.optus.net
     * updates: mirror.optus.net
    --> Processing Dependency: ldns >= 1.6.13 for package: unbound-1.4.20-26.el7.x86_64
    --> Processing Dependency: libevent-2.0.so.5()(64bit) for package: unbound-1.4.20-26.el7.x86_64
    --> Processing Dependency: libldns.so.1()(64bit) for package: unbound-1.4.20-26.el7.x86_64
    --> Processing Dependency: libunbound.so.2()(64bit) for package: unbound-1.4.20-26.el7.x86_64
    --> Running transaction check
    ---> Package ldns.x86_64 0:1.6.16-7.el7 will be installed
    ---> Package libevent.x86_64 0:2.0.21-4.el7 will be installed
    ---> Package unbound-libs.x86_64 0:1.4.20-26.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =========================================================================================
     Package          Arch       Version             Repository                         Size
    =========================================================================================
    Installing:
     unbound          x86_64     1.4.20-26.el7       /unbound-1.4.20-26.el7.x86_64     1.6 M
    Installing for dependencies:
     ldns             x86_64     1.6.16-7.el7        base                              473 k
     libevent         x86_64     2.0.21-4.el7        base                              214 k
     unbound-libs     x86_64     1.4.20-26.el7       base                              296 k
    
    Transaction Summary
    =========================================================================================
    Install  1 Package (+3 Dependent packages)
    
    Total size: 2.6 M
    Total download size: 982 k
    Installed size: 4.4 M
    Is this ok [y/d/N]: y
    Downloading packages:
    (1/3): unbound-libs-1.4.20-26.el7.x86_64.rpm                      | 296 kB  00:00:00
    (2/3): ldns-1.6.16-7.el7.x86_64.rpm                               | 473 kB  00:00:00
    (3/3): libevent-2.0.21-4.el7.x86_64.rpm                           | 214 kB  00:00:00
    -----------------------------------------------------------------------------------------
    Total                                                       1.5 MB/s | 982 kB  00:00
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : ldns-1.6.16-7.el7.x86_64                                              1/4
      Installing : libevent-2.0.21-4.el7.x86_64                                          2/4
      Installing : unbound-libs-1.4.20-26.el7.x86_64                                     3/4
      Installing : unbound-1.4.20-26.el7.x86_64                                          4/4
      Verifying  : unbound-1.4.20-26.el7.x86_64                                          1/4
      Verifying  : unbound-libs-1.4.20-26.el7.x86_64                                     2/4
      Verifying  : libevent-2.0.21-4.el7.x86_64                                          3/4
      Verifying  : ldns-1.6.16-7.el7.x86_64                                              4/4
    
    Installed:
      unbound.x86_64 0:1.4.20-26.el7
    
    Dependency Installed:
      ldns.x86_64 0:1.6.16-7.el7                    libevent.x86_64 0:2.0.21-4.el7
      unbound-libs.x86_64 0:1.4.20-26.el7
    
    Complete!
    
  • 7. Uninstall Package

    Packages can be uninstalled with the ‘remove’ argument, as shown below.

    [root@centos7 ~]# yum remove httpd
    Loaded plugins: fastestmirror
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be erased
    --> Processing Dependency: httpd = 2.4.6-40.el7.centos.4 for package: httpd-manual-2.4.6-40.el7.centos.4.noarch
    --> Running transaction check
    ---> Package httpd-manual.noarch 0:2.4.6-40.el7.centos.4 will be erased
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =============================================================================================================================================================================================
     Package                                      Arch                                   Version                                                  Repository                                Size
    =============================================================================================================================================================================================
    Removing:
     httpd                                        x86_64                                 2.4.6-40.el7.centos.4                                    @updates                                 9.4 M
    Removing for dependencies:
     httpd-manual                                 noarch                                 2.4.6-40.el7.centos.4                                    @updates                                 5.5 M
    
    Transaction Summary
    =============================================================================================================================================================================================
    Remove  1 Package (+1 Dependent package)
    
    Installed size: 15 M
    Is this ok [y/N]: y
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Erasing    : httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                 1/2
      Erasing    : httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        2/2
      Verifying  : httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                 1/2
      Verifying  : httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        2/2
    
    Removed:
      httpd.x86_64 0:2.4.6-40.el7.centos.4
    
    Dependency Removed:
      httpd-manual.noarch 0:2.4.6-40.el7.centos.4
    
    Complete!
    

    Note that in order to remove a package, all other packages which depend on it will also be removed. For that reason it is recommended not to use the -y option to ‘assumeyes’ when removing a package so that you get a chance to read what will be removed before proceeding, as it may be more than you expect.

    In the above example, the httpd-manual package that we installed previously requires the httpd package. Therefore when we remove the httpd package, httpd-manual must go too.

  • 8. Reinstall Package

    If you’re having a problem with a package, you can easily reinstall it with the ‘reinstall’ argument.

    [root@centos7 ~]# yum reinstall httpd -y
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror.ventraip.net.au
     * extras: mirror.optus.net
     * updates: mirror.optus.net
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be reinstalled
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =============================================================================================================================================================================================
     Package                                 Arch                                     Version                                                    Repository                                 Size
    =============================================================================================================================================================================================
    Reinstalling:
     httpd                                   x86_64                                   2.4.6-40.el7.centos.4                                      updates                                   2.7 M
    
    Transaction Summary
    =============================================================================================================================================================================================
    Reinstall  1 Package
    
    Total download size: 2.7 M
    Installed size: 9.4 M
    Downloading packages:
    httpd-2.4.6-40.el7.centos.4.x86_64.rpm                                                                                                                                | 2.7 MB  00:00:00
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        1/1
      Verifying  : httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        1/1
    
    Installed:
      httpd.x86_64 0:2.4.6-40.el7.centos.4
    
    Complete!
    

    This is similar to performing a ‘yum remove’ followed by a ‘yum install’, however here it’s done in the one command and custom configuration is not removed, as a ‘yum remove’ will delete all configuration files managed by the package.

  • 9. View Repository Information

    By default we have many repositories configured in the /etc/yum.repos.d/ directory, these can be viewed with the ‘repolist’ and ‘repoinfo’ arguments.

    [root@centos7 ~]# yum repolist
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror.ventraip.net.au
     * extras: mirror.optus.net
     * updates: mirror.optus.net
    repo id                 repo name               status
    base/7/x86_64           CentOS-7 - Base         9,007
    extras/7/x86_64         CentOS-7 - Extras       375
    updates/7/x86_64        CentOS-7 - Updates      2,303
    repolist: 11,685
    

    By default ‘repolist’ displays information for enabled repositories only, however we can specify ‘all’ afterwards to list even disabled repositories.

    [root@centos7 ~]# yum repolist all
    
    repo id                      repo name                   status
    base/7/x86_64                CentOS-7 - Base             enabled: 9,007
    base-debuginfo/x86_64        CentOS-7 - Debuginfo        disabled
    base-source/7                CentOS-7 - Base Sources     disabled
    c7-media                     CentOS-7 - Media            disabled
    centosplus/7/x86_64          CentOS-7 - Plus             disabled
    ...
    

    Further information on a specific repository can then be viewed with ‘repoinfo’ followed by the repo name that you want to query.

    [root@centos7 ~]# yum repoinfo CentOS-7 - Base
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror.ventraip.net.au
     * extras: mirror.optus.net
     * updates: mirror.optus.net
    Repo-id      : base/7/x86_64
    Repo-name    : CentOS-7 - Base
    Repo-status  : enabled
    Repo-revision: 1449700451
    Repo-updated : Thu Dec 10 09:35:45 2015
    Repo-pkgs    : 9,007
    Repo-size    : 6.5 G
    Repo-mirrors : http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock
    Repo-baseurl : http://mirror.ventraip.net.au/CentOS/7.2.1511/os/x86_64/ (9 more)
    Repo-expire  : 21,600 second(s) (last: Mon Aug 29 14:25:35 2016)
    Repo-filename: /etc/yum.repos.d/CentOS-Base.repo
    
    repolist: 9,007
    
  • 10. Add New Repository

    We can specify a new repository by manually editing or creating a new .repo file in the /etc/yum.repos.d directory, however we can much more easily create a persistent repository with the yum-config-manager command. This command comes from the ‘yum-utils’ package which we installed previously, so if you wish to use ‘yum-config-manager’ be sure to first install ‘yum-utils’.

    [root@centos7 ~]# yum-config-manager --add-repo="https://mirror.aarnet.edu.au/pub/centos/7"
    Loaded plugins: fastestmirror
    adding repo from: https://mirror.aarnet.edu.au/pub/centos/7
    
    [mirror.aarnet.edu.au_pub_centos_7]
    name=added from: https://mirror.aarnet.edu.au/pub/centos/7
    baseurl=https://mirror.aarnet.edu.au/pub/centos/7
    enabled=1
    

    We simply provide a known repository URL in the –add-repo option, and this creates a .repo file based on the name of the repository URL specified. In this case, /etc/yum.repos.d/mirror.aarnet.edu.au_pub_centos_7.repo has been created with the contents specified above in the output of the command. We can now install or update packages from this newly specified mirror.

  • 11. Enable Or Disable Specific Repository

    There may be times when we want to perform an action while enabling or disabling a specific repository. For example if we want to install a particular package, we may want to ensure that it comes from a specific mirror.

    yum --enablerepo=disabled-repo install package-example
    

    This would enabled a previously disabled repo named ‘disabled-repo’ in order to install ‘package-example’ from it.

    If we have the same packages available at multiple repositories we may wish to disable one and update or install from a specific repository. This can be done by disabling the repository with --disablerepo.

    yum --disablerepo=enabled-repo install package-example
    
  • 12. Search For Packages In Repository

    The ‘search’ argument is a very useful yum feature, as it allows us to search through packages on the repository which can be useful if we don’t know exactly what we’re looking to install.

    [root@centos7 ~]# yum search php
    ===================================================================================== N/S matched: php ======================================================================================
    graphviz-php.x86_64 : PHP extension for graphviz
    php.x86_64 : PHP scripting language for creating dynamic web sites
    php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
    php-cli.x86_64 : Command-line interface for PHP
    php-common.x86_64 : Common files for PHP
    php-dba.x86_64 : A database abstraction layer module for PHP applications
    php-devel.x86_64 : Files needed for building PHP extensions
    php-embedded.x86_64 : PHP library for embedding in applications
    php-enchant.x86_64 : Enchant spelling extension for PHP applications
    php-fpm.x86_64 : PHP FastCGI Process Manager
    php-gd.x86_64 : A module for PHP applications for using the gd graphics library
    ...
      Name and summary matches only, use "search all" for everything.
    

    In this example we search package names and the summary for the term “PHP” and see a number of available packages at the repositories ready for us to install or download.

  • 13. Find Which Package Provides Something

    This is one of my favourite features of the yum command as it’s very useful. Have you ever wanted to run a command, but you’re not sure which package is required for it? This is where the ‘provides’ argument comes in use.

    In this example we want to create an iSCSI initiator, this is done with the ‘iscsiadm’ command. We can use ‘provides’ followed by the name of the command to search for packages that provide this command.

    [root@centos7 ~]# yum provides iscsiadm
    iscsi-initiator-utils-6.2.0.873-32.el7.i686 : iSCSI daemon and utility programs
    Repo        : base
    Matched from:
    Filename    : /usr/sbin/iscsiadm
    

    As shown the ‘iscsi-initiator-utils’ package can be installed to provide the ‘iscsiadm’ command.

    This can also be used against a file on the file system to check which package provides that file.

    [root@centos7 ~]# yum provides /etc/httpd/conf/httpd.conf
    httpd-2.4.6-40.el7.centos.x86_64 : Apache HTTP Server
    Repo        : base
    Matched from:
    Filename    : /etc/httpd/conf/httpd.conf
    

    In this example we can see that the /etc/httpd/conf/httpd.conf file comes from the ‘httpd’ package.

  • 14. View Package Information

    Further detailed information of a package can be viewed with the ‘info’ argument. As shown below, this provides us with useful information such as the architecture, version number, release number, total size, as well as a description of what the package actually does.

    [root@centos7 ~]# yum info httpd
    Available Packages
    Name        : httpd
    Arch        : x86_64
    Version     : 2.4.6
    Release     : 40.el7.centos.4
    Size        : 2.7 M
    Repo        : updates/7/x86_64
    Summary     : Apache HTTP Server
    URL         : http://httpd.apache.org/
    License     : ASL 2.0
    Description : The Apache HTTP Server is a powerful, efficient, and extensible
                : web server.
    

    This can be used before a package is installed or after installation, the same information will be provided in both situations.

  • 15. View Transaction History

    The yum history contains all actions that have been performed by the yum command. This allows us to see what has happened to our Linux system over time, and even undo, redo, or roll back a transaction.

    [root@centos7 ~]# yum history
    ID     | Login user      | Date and time    | Action(s)      | Altered
    ------------------------------------------------------------------------
        15 | root            | 2016-08-29 15:20 | Erase          |    1
        14 | root            | 2016-08-29 14:55 | Install        |    1
        13 | root            | 2016-08-29 14:55 | Erase          |    1 EE
        12 | root            | 2016-08-29 14:54 | Reinstall      |    1
        11 | root            | 2016-08-29 14:54 | Install        |   31
        10 | root            | 2016-08-29 14:53 | Install        |    1
         9 | root            | 2016-08-29 14:47 | Erase          |    2
         8 | root            | 2016-08-29 14:45 | Install        |    4
         7 | root            | 2016-08-29 14:40 | Install        |    3
         6 | root            | 2016-08-29 14:37 | Update         |    1
         5 | root            | 2016-08-29 14:32 | Install        |    1
         4 | root            | 2016-08-29 14:28 | Install        |    1
         3 | root            | 2016-08-29 14:28 | Erase          |    1
         2 | root            | 2016-08-29 14:28 | Install        |    5
         1 | System          | 2016-08-29 14:17 | Install        |  298
    history list
    

    The newest transactions appear at the top of the list, and we can view further information of a transaction by specifying its ID, as shown below.

    [root@centos7 ~]# yum history info 15
    Transaction ID : 15
    Begin time     : Mon Aug 29 15:20:57 2016
    Begin rpmdb    : 341:c62a7835aef7986909a89bc51d654acf51b8d756
    End time       :                           (0 seconds)
    End rpmdb      : 340:8701e1360e8e5403f96a5cc61994740ba7d8daf8
    User           : root 
    Return-Code    : Success
    Command Line   : remove httpd -y
    Transaction performed with:
        Installed     rpm-4.11.3-17.el7.x86_64                      @anaconda
        Installed     yum-3.4.3-132.el7.centos.0.1.noarch           @anaconda
        Installed     yum-plugin-fastestmirror-1.1.31-34.el7.noarch @anaconda
    Packages Altered:
        Erase httpd-2.4.6-40.el7.centos.4.x86_64 @updates
    history info
    

    So the most recent transaction with the ID of 15 was used to remove the httpd package. Now we can undo this transaction if we want, which should install the httpd package again, as this will undo the removal.

    [root@centos7 ~]# yum history undo 15 -y
    Undoing transaction 15, from Mon Aug 29 15:20:57 2016
        Erase httpd-2.4.6-40.el7.centos.4.x86_64 @updates
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ============================================================================
     Package              Arch      Version                 Repository    Size
    ============================================================================
    Installing:
     httpd               x86_64    2.4.6-40.el7.centos.4    updates       2.7 M
    
    Transaction Summary
    ============================================================================
    Install  1 Package
    
    Total download size: 2.7 M
    Installed size: 9.4 M
    Downloading packages:
    httpd-2.4.6-40.el7.centos.4.x86_64.rpm                   | 2.7 MB  00:00:00
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : httpd-2.4.6-40.el7.centos.4.x86_64                       1/1
      Verifying  : httpd-2.4.6-40.el7.centos.4.x86_64                       1/1
    
    Installed:
      httpd.x86_64 0:2.4.6-40.el7.centos.4
    
    Complete!
    

    We can then run the removal again with ‘yum history redo’.

    [root@centos7 ~]# yum history redo 15 -y
    Repeating transaction 15, from Mon Aug 29 15:20:57 2016
        Erase httpd-2.4.6-40.el7.centos.4.x86_64 @updates
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be erased
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==========================================================================
     Package              Arch       Version                Repository   Size
    ==========================================================================
    Removing:
     httpd                x86_64     2.4.6-40.el7.centos.4  @updates    9.4 M
    
    Transaction Summary
    ==========================================================================
    Remove  1 Package
    
    Installed size: 9.4 M
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Erasing    : httpd-2.4.6-40.el7.centos.4.x86_64  1/1
      Verifying  : httpd-2.4.6-40.el7.centos.4.x86_64  1/1
    
    Removed:
      httpd.x86_64 0:2.4.6-40.el7.centos.4
    
    Complete!
    

    It’s also worth noting that package installations, updates, or removals are also logged in the /var/log/yum.log file, here’s an example of what’s logged here.

    [root@centos7 ~]# tail /var/log/yum.log
    Aug 29 14:28:24 Installed: httpd-2.4.6-40.el7.centos.4.x86_64
    Aug 29 14:28:29 Erased: httpd-2.4.6-40.el7.centos.4.x86_64
    Aug 29 14:28:41 Installed: httpd-2.4.6-40.el7.centos.4.x86_64
    Aug 29 14:32:55 Installed: httpd-manual-2.4.6-40.el7.centos.4.noarch
    Aug 29 14:37:28 Updated: bash-4.2.46-20.el7_2.x86_64
    
  • 16. Clear Cached Information

    By default yum will cache data to the /var/cache/yum directory, such as package and repository data. This speeds up yum so that it doesn’t have to keep querying this information from the Internet.

    There are times when you may want to delete this cached data, such as if a repository has updated packages but your Linux system has incorrect or stale cached data which may cause various problems when attempting to install a package.

    [root@centos7 ~]# yum clean all
    Loaded plugins: fastestmirror
    Cleaning repos: base extras updates
    Cleaning up everything
    Cleaning up list of fastest mirrors
    

    This will remove all cached items, it is possible to otherwise specify specific elements to clear (such as packages, metadata, expire-cache, rpmdb or plugins) however this saves a lot of time if you aren’t sure what should be removed.

  • 17. Build Cache

    The yum cache will be automatically built up over time when you perform various yum queries such as installing or updating packages, however we have the option to manually make the cache so that future actions will be quicker with the ‘makecache’ argument.

    [root@centos7 ~]# time yum makecache
    Loaded plugins: fastestmirror, langpacks
    base                                            | 3.6 kB  00:00:00
    extras                                          | 3.4 kB  00:00:00
    updates                                         | 3.4 kB  00:00:00
    (1/12): base/7/x86_64/group_gz                  | 155 kB  00:00:00
    (2/12): extras/7/x86_64/prestodelta             |  72 kB  00:00:00
    (3/12): extras/7/x86_64/filelists_db            | 426 kB  00:00:00
    (4/12): extras/7/x86_64/primary_db              | 160 kB  00:00:00
    (5/12): base/7/x86_64/filelists_db              | 6.2 MB  00:00:01
    (6/12): extras/7/x86_64/other_db                | 652 kB  00:00:00
    (7/12): base/7/x86_64/other_db                  | 2.3 MB  00:00:01
    (8/12): updates/7/x86_64/prestodelta            | 698 kB  00:00:00
    (9/12): base/7/x86_64/primary_db                | 5.3 MB  00:00:01
    (10/12): updates/7/x86_64/filelists_db          | 4.4 MB  00:00:01
    (11/12): updates/7/x86_64/primary_db            | 7.1 MB  00:00:01
    (12/12): updates/7/x86_64/other_db              |  61 MB  00:00:07
    Determining fastest mirrors
     * base: centos.mirror.crucial.com.au
     * extras: centos.mirror.crucial.com.au
     * updates: centos.mirror.crucial.com.au
    Metadata Cache Created
    
    real    0m40.785s
    user    0m32.504s
    sys     0m1.937s
    

    We can also add the ‘fast’ option to the end, which will take less time but only cache fewer repositories.

    [root@centos7 ~]# time yum makecache fast
    Loaded plugins: fastestmirror, langpacks
    base                                     | 3.6 kB  00:00:00
    extras                                   | 3.4 kB  00:00:00
    updates                                  | 3.4 kB  00:00:00
    (1/4): base/7/x86_64/group_gz            | 155 kB  00:00:00
    (2/4): extras/7/x86_64/primary_db        | 160 kB  00:00:00
    (3/4): base/7/x86_64/primary_db          | 5.3 MB  00:00:00
    (4/4): updates/7/x86_64/primary_db       | 7.1 MB  00:00:01
    Determining fastest mirrors
     * base: mirror.nsw.coloau.com.au
     * extras: mirror.nsw.coloau.com.au
     * updates: mirror.nsw.coloau.com.au
    Metadata Cache Created
    
    real    0m8.879s
    user    0m3.451s
    sys     0m0.343s
    

    As we can see the fast cache was significantly faster.

  • 18. List Installed Packages

    We have the ability to list all packages that are currently installed on our Linux system with ‘yum list installed’. I have not included the full output here as I have hundreds of packages installed on my system, however this small snippet should give you an idea of what to expect.

    [root@centos7 ~]# yum list installed | head -n 15
    Installed Packages
    NetworkManager.x86_64                1:1.0.6-30.el7_2             @anaconda
    NetworkManager-libnm.x86_64          1:1.0.6-30.el7_2             @anaconda
    NetworkManager-team.x86_64           1:1.0.6-30.el7_2             @anaconda
    NetworkManager-tui.x86_64            1:1.0.6-30.el7_2             @anaconda
    NetworkManager-wifi.x86_64           1:1.0.6-30.el7_2             @anaconda
    acl.x86_64                           2.2.51-12.el7                @anaconda
    aic94xx-firmware.noarch              30-6.el7                     @anaconda
    alsa-firmware.noarch                 1.0.28-2.el7                 @anaconda
    alsa-lib.x86_64                      1.0.28-2.el7                 @anaconda
    alsa-tools-firmware.x86_64           1.0.28-2.el7                 @anaconda
    apr.x86_64                           1.4.8-3.el7                  @base
    apr-util.x86_64                      1.5.2-6.el7                  @base
    audit.x86_64                         2.4.1-5.el7                  @anaconda
    ...
    

    When piped into the grep command this becomes extremely powerful as it allows us to search for a specific package to see if it is installed.

    [root@centos7 ~]# yum list installed | grep httpd
    httpd.x86_64                         2.4.6-40.el7.centos.4          @updates
    httpd-tools.x86_64                   2.4.6-40.el7.centos.4          @updates
    
  • 19. List Available Packages

    In the above example we learned how to list currently installed packages on our Linux system with the yum command, now we want to be able to query a repository and list its available packages instead.

    This is quite similar, except that we replace ‘installed’ with ‘available’ to instead list all available packages.

    [root@centos7 ~]# yum list installed | wc -l
    343
    [root@centos7 ~]# yum list available | wc -l
    8972
    

    As we can see we have over 300 packages currently installed, however in the repository there are almost 9000 packages in total for us to install.

    We can also run ‘yum list all’ to list both installed and available packages together, or ‘yum list updates’ to only list packages which currently have updates available, the output of which is similar to the ‘yum check-update’ command covered previously.

  • 20. Package Groups

    Packages that are related to each other may be grouped together into a package group. This allows us to install, update, or remove the package group which is actually made up or many other individual packages.

    For example we can run ‘yum grouplist’ to view the groups that are available for us to use by default.

    [root@centos7 ~]# yum grouplist
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    Available Environment Groups:
       Minimal Install
       Compute Node
       Infrastructure Server
       File and Print Server
       Basic Web Server
       Virtualization Host
       Server with GUI
       GNOME Desktop
       KDE Plasma Workspaces
       Development and Creative Workstation
    Available Groups:
       Compatibility Libraries
       Console Internet Tools
       Development Tools
       Graphical Administration Tools
       Legacy UNIX Compatibility
       Scientific Support
       Security Tools
       Smart Card Support
       System Administration Tools
       System Management
    Done
    

    Once we have the list of available groups, we can use ‘yum groupinfo’ on any of them to get an idea of the packages that are included as part of the group.

    [root@centos7 ~]# yum groupinfo "Basic Web Server"
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    
    Environment Group: Basic Web Server
     Environment-Id: web-server-environment
     Description: Server for serving static and dynamic internet content.
     Mandatory Groups:
       +base
       +core
       +web-server
    
    [root@centos7 ~]# yum groupinfo "web-server"
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    
    Group: Web Server
     Group-Id: web-server
     Description: Allows the system to act as a web server, and run Perl and Python web applications.
     Mandatory Packages:
        httpd
     Default Packages:
       +crypto-utils
       +httpd-manual
       +mod_fcgid
       +mod_ssl
    

    Here we can see the “Basic Web Server” group is actually made up of three other groups, base, core, and web-server. If we look closer at the web-server group we can see that it uses the httpd package as well as some additional ones that we do not yet have installed but are available, as denoted by the ‘+’ symbol.

    Finally we can install the group with the ‘yum groupinstall’ command, as shown below.

    [root@centos7 ~]# yum groupinstall "web server" -y
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    Resolving Dependencies
    --> Running transaction check
    ---> Package crypto-utils.x86_64 0:2.4.1-42.el7 will be installed
    --> Processing Dependency: perl(Newt) for package: crypto-utils-2.4.1-42.el7.x86_64
    ---> Package httpd-manual.noarch 0:2.4.6-40.el7.centos.4 will be installed
    ---> Package mod_fcgid.x86_64 0:2.3.9-4.el7 will be installed
    ---> Package mod_ssl.x86_64 1:2.4.6-40.el7.centos.4 will be installed
    --> Running transaction check
    ---> Package perl-Newt.x86_64 0:1.08-36.el7 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =============================================================================================================================================================================================
     Package                                      Arch                                   Version                                                   Repository                               Size
    =============================================================================================================================================================================================
    Installing for group install "Web Server":
     crypto-utils                                 x86_64                                 2.4.1-42.el7                                              base                                     78 k
     httpd-manual                                 noarch                                 2.4.6-40.el7.centos.4                                     updates                                 1.3 M
     mod_fcgid                                    x86_64                                 2.3.9-4.el7                                               base                                     79 k
     mod_ssl                                      x86_64                                 1:2.4.6-40.el7.centos.4                                   updates                                 104 k
    Installing for dependencies:
     perl-Newt                                    x86_64                                 1.08-36.el7                                               base                                     64 k
    
    Transaction Summary
    =============================================================================================================================================================================================
    Install  4 Packages (+1 Dependent package)
    
    Total download size: 1.6 M
    Installed size: 6.2 M
    Downloading packages:
    (1/5): crypto-utils-2.4.1-42.el7.x86_64.rpm                                                                                                                           |  78 kB  00:00:00
    (2/5): perl-Newt-1.08-36.el7.x86_64.rpm                                                                                                                               |  64 kB  00:00:00
    (3/5): mod_fcgid-2.3.9-4.el7.x86_64.rpm                                                                                                                               |  79 kB  00:00:00
    (4/5): mod_ssl-2.4.6-40.el7.centos.4.x86_64.rpm                                                                                                                       | 104 kB  00:00:00
    (5/5): httpd-manual-2.4.6-40.el7.centos.4.noarch.rpm                                                                                                                  | 1.3 MB  00:00:00
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                                                                        2.5 MB/s | 1.6 MB  00:00:00
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Installing : perl-Newt-1.08-36.el7.x86_64                                                                                                                                              1/5
      Installing : crypto-utils-2.4.1-42.el7.x86_64                                                                                                                                          2/5
      Installing : 1:mod_ssl-2.4.6-40.el7.centos.4.x86_64                                                                                                                                    3/5
      Installing : httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                 4/5
      Installing : mod_fcgid-2.3.9-4.el7.x86_64                                                                                                                                              5/5
      Verifying  : perl-Newt-1.08-36.el7.x86_64                                                                                                                                              1/5
      Verifying  : mod_fcgid-2.3.9-4.el7.x86_64                                                                                                                                              2/5
      Verifying  : crypto-utils-2.4.1-42.el7.x86_64                                                                                                                                          3/5
      Verifying  : httpd-manual-2.4.6-40.el7.centos.4.noarch                                                                                                                                 4/5
      Verifying  : 1:mod_ssl-2.4.6-40.el7.centos.4.x86_64                                                                                                                                    5/5
    
    Installed:
      crypto-utils.x86_64 0:2.4.1-42.el7          httpd-manual.noarch 0:2.4.6-40.el7.centos.4          mod_fcgid.x86_64 0:2.3.9-4.el7          mod_ssl.x86_64 1:2.4.6-40.el7.centos.4
    
    Dependency Installed:
      perl-Newt.x86_64 0:1.08-36.el7
    
    Complete!
    

    The group can also be updated with ‘yum groupupdate’, or all packages within the group removed with ‘yum groupremove’.

  • 21. Install Security Updates Only

    While we can simply perform a ‘yum update’ to update all of our installed packages to the latest versions, this may not be ideal in a production environment. Being able to install security only updates during patching may be a requirement in your environment, and can be done with ‘yum update --security’.

    [root@centos7 ~]# yum update --security
    
  • 22. Exclude Specific Package

    We can optionally exclude a specific package from update, installation or removal with the -x command which will exclude that package. In this example, we perform a ‘yum check-update’ and confirm that a kernel update is available, however we do not wish to install this package at this time. With the help of -x, we ignore the kernel update and instead perform a ‘yum update’ which states that it is going to update everything except the kernel, which is not listed.

    [root@centos7 ~]# yum check-update
    
    device-mapper-persistent-data.x86_64                                                               0.6.2-1.el7_2                                                                      updates
    initscripts.x86_64                                                                                 9.49.30-1.el7_2.3                                                                  updates
    kernel.x86_64                                                                                      3.10.0-327.28.3.el7                                                                updates
    kernel-tools.x86_64                                                                                3.10.0-327.28.3.el7                                                                updates
    kernel-tools-libs.x86_64                                                                           3.10.0-327.28.3.el7                                                                updates
    microcode_ctl.x86_64                                                                               2:2.1-12.el7_2.1                                                                   updates
    python-perf.x86_64                                                                                 3.10.0-327.28.3.el7                                                                updates
    
    [root@centos7 ~]# yum update -x kernel
    Resolving Dependencies
    --> Running transaction check
    ---> Package device-mapper-persistent-data.x86_64 0:0.5.5-1.el7 will be updated
    ---> Package device-mapper-persistent-data.x86_64 0:0.6.2-1.el7_2 will be an update
    ---> Package initscripts.x86_64 0:9.49.30-1.el7_2.2 will be updated
    ---> Package initscripts.x86_64 0:9.49.30-1.el7_2.3 will be an update
    ---> Package kernel-tools.x86_64 0:3.10.0-327.22.2.el7 will be updated
    ---> Package kernel-tools.x86_64 0:3.10.0-327.28.3.el7 will be an update
    ---> Package kernel-tools-libs.x86_64 0:3.10.0-327.22.2.el7 will be updated
    ---> Package kernel-tools-libs.x86_64 0:3.10.0-327.28.3.el7 will be an update
    ---> Package microcode_ctl.x86_64 2:2.1-12.el7 will be updated
    ---> Package microcode_ctl.x86_64 2:2.1-12.el7_2.1 will be an update
    ---> Package python-perf.x86_64 0:3.10.0-327.22.2.el7 will be updated
    ---> Package python-perf.x86_64 0:3.10.0-327.28.3.el7 will be an update
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =============================================================================================================================================================================================
     Package                                                    Arch                                Version                                           Repository                            Size
    =============================================================================================================================================================================================
    Updating:
     device-mapper-persistent-data                              x86_64                              0.6.2-1.el7_2                                     updates                              366 k
     initscripts                                                x86_64                              9.49.30-1.el7_2.3                                 updates                              429 k
     kernel-tools                                               x86_64                              3.10.0-327.28.3.el7                               updates                              2.4 M
     kernel-tools-libs                                          x86_64                              3.10.0-327.28.3.el7                               updates                              2.3 M
     microcode_ctl                                              x86_64                              2:2.1-12.el7_2.1                                  updates                              535 k
     python-perf                                                x86_64                              3.10.0-327.28.3.el7                               updates                              2.4 M
    
    Transaction Summary
    =============================================================================================================================================================================================
    Upgrade  6 Packages
    
    Total download size: 8.4 M
    Is this ok [y/d/N]:
    
  • 23. Add Random Wait Time

    There are times where you may want to insert a random period of time before performing some yum command, for example if you manage hundreds of servers and go to update them all on a particular day you probably don’t want them all to hit the repository at the same time as this may cause the process to run very slow. With the -R option we can specify a maximum random time in minutes that yum will wait before executing the command, somewhere within this time period will be selected at random.

    [root@centos7 ~]# time yum remove httpd -y -R 2
    Loaded plugins: fastestmirror
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be erased
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    =============================================================================================================================================================================================
     Package                                 Arch                                     Version                                                   Repository                                  Size
    =============================================================================================================================================================================================
    Removing:
     httpd                                   x86_64                                   2.4.6-40.el7.centos.4                                     @updates                                   9.4 M
    
    Transaction Summary
    =============================================================================================================================================================================================
    Remove  1 Package
    
    Installed size: 9.4 M
    Downloading packages:
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      Erasing    : httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        1/1
      Verifying  : httpd-2.4.6-40.el7.centos.4.x86_64                                                                                                                                        1/1
    
    Removed:
      httpd.x86_64 0:2.4.6-40.el7.centos.4
    
    Complete!
    
    real    1m21.954s
    user    0m0.409s
    sys     0m0.156s
    

    In this example I appended the ‘time’ command to the ‘yum’ command so that we could see how long it took to complete, in this example we can see that this took approximately 1 minute and 22 seconds to complete, which is a random period from 0 to 2 minutes as was specified.

  • 24. Hide All Output

    As you have seen in the above examples, the yum command can provide quite a bit of output. If we don’t want to display the output messages we can simply specify the -q option for quiet which will hide all of the output. In the example below we completely uninstall a package with yum and have no messages output.

    [root@centos7 ~]# yum install httpd -y -q
    [root@centos7 ~]#
    
  • 25. Display Verbose Information

    Alternatively if you’re troubleshooting you can specify the -v option to enable verbose output. In the below verbose example we can see additional information in the output that was not previously available.

    [root@centos7 ~]# yum remove httpd -y -v
    Loading "fastestmirror" plugin
    Config time: 0.007
    Yum version: 3.4.3
    rpmdb time: 0.000
    Resolving Dependencies
    --> Running transaction check
    ---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 will be erased
    Checking deps for httpd.x86_64 0:2.4.6-40.el7.centos.4 - e
    --> Finished Dependency Resolution
    Dependency Process ending
    Depsolve time: 0.220
    
    Dependencies Resolved
    
    =========================================================================
     Package              Arch       Version                Repository   Size
    =========================================================================
    Removing:
     httpd                x86_64     2.4.6-40.el7.centos.4  @updates    9.4 M
    
    Transaction Summary
    =========================================================================
    Remove  1 Package
    
    Installed size: 9.4 M
    Downloading packages:
    Member: httpd.x86_64 0:2.4.6-40.el7.centos.4 - e
    Removing Package httpd-2.4.6-40.el7.centos.4.x86_64
    Running transaction check
    Transaction check time: 0.001
    Running transaction test
    Transaction test succeeded
    Transaction test time: 0.014
    Running transaction
      Erasing    : httpd-2.4.6-40.el7.centos.4.x86_64     1/1
      Verifying  : httpd-2.4.6-40.el7.centos.4.x86_64     1/1
    VerifyTransaction time: 0.049
    Transaction time: 0.425
    
    Removed:
      httpd.x86_64 0:2.4.6-40.el7.centos.4
    
    Complete!
    

Summary

This guide has covered how to use yum with 25 different examples in which you can practically put the yum command to use.

Leave a comment ?

10 Comments.

  1. Thanks for this usefull list !!

  2. Nice list.

  3. How do I find which repo contains a package I want? repolist all shows 58 disabled repos. Short of enable and try to search each one. Is there a way to search for a package on all the repos including disabled ones?

    Thanks.

  4. You may also use this:

    yum provides zlib –enablerepo=*

  5. yum provides zlib –enablerepo=*

  6. PROF RAJIV BANERJI

    Excellent beyond excellente!

  7. Ritik kumar jain

    can you tell me where did you get this shell layout for wordpress

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>