YUM command to manage packages on RHEL/CentOS/ systems

Linux package managers make the life of the administrator much easier by taking care of dependency resolution.

Yum (Yellowdog Updater Modified) is one of the package manager, which is used in RPM based systems such as RHL, CentOS and Oracle Linux.

But starting from RHEL 8/CentOS 8/OL 8 it uses DNF on the back of yum.

What is YUM?

Yum is a free and open-source command-line package-management application for Linux operating systems that uses the RPM Package Manager.

Yum is a front-end tool for rpm that automatically solves dependencies for packages.

It installs RPM software packages from distribution official repositories and other third-party repositories.

Yum allows you to install, update, search and remove packages from your system.

If you want to keep your system up-to-date, you can enable automatic updates via yum-cron.

Also, it allows you to exclude a package or packages from the yum update if you need to.

Each Linux distribution has their own package manager, check the following link to check them all out.

Yum is installed by default and you do not need to install it.

The General Syntax of the YUM Command

The syntax of the YUM command as follows.

yum [Option] [Command] [Package_Name]

Location of the YUM Configuration Files

Main Configuration File: /etc/yum.conf
Other Repository Files: /etc/yum.repos.d/
Cache Files: /var/cache/yum
Logfile: /var/log/yum.log
Yum plugin configuration: /etc/yum/pluginconf.d/
/etc/yum/version-groups.conf

2) How to List Repositories on CentOS/RHEL/Oracle Linux Using the yum Command

This command print a list of configured repositories on your system.

By default it lists all the repositories that are enabled. Add -v to verbose mode, which gives you more information.

To list the repositories that are enabled, run the command below on your system.

# yum repolist

Loaded plugins: fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
 * base: centos.hbcse.tifr.res.in
 * centos-sclo-rh: centos.hbcse.tifr.res.in
 * centos-sclo-sclo: centos.mirrors.estointernet.in
 * epel: epel.dionipe.id
 * extras: centos.hbcse.tifr.res.in
 * remi-safe: ftp.riken.jp
 * updates: centos.mirrors.estointernet.in
repo id                                                                              repo name                                                                                                               status
!base/7/x86_64                                                                       CentOS-7 - Base                                                                                                         10,097
!centos-sclo-rh/x86_64                                                               CentOS-7 - SCLo rh                                                                                                       8,869
!centos-sclo-sclo/x86_64                                                             CentOS-7 - SCLo sclo                                                                                                       872
!epel/x86_64                                                                         Extra Packages for Enterprise Linux 7 - x86_64                                                                          13,520
!extras/7/x86_64                                                                     CentOS-7 - Extras                                                                                                          323
!ius/x86_64                                                                          IUS for Enterprise Linux 7 - x86_64                                                                                        867
!remi-safe                                                                           Safe Remi's RPM repository for Enterprise Linux 7 - x86_64                                                               3,673
!updates/7/x86_64                                                                    CentOS-7 - Updates                                                                                                       1,117
repolist: 39,338

Alternatively, you can run the following command to list the enabled repositories on the system.

# yum repolist enabled

Run the following command to list the disabled repositories on the system.

# yum repolist disabled

Run the following command to list all repositories (enabled and disabled) on the system.

# yum repolist all

To see detailed information about each of the repositories, add the -v switch with the yum command. It displays repo-id, repo-name and so on.

# yum repolist -v

3) How to Install a Package or Packages on CentOS/RHEL/Oracle Linux Systems Using the yum Command

To install a package or package on CentOS/RHEL/Oracle Linux systems, use the below yum command.

In our case, we are going to install nano, MariaDB-server and MariaDB-client packages. By default, every time yum asks for your confirmation to install a package, and add the -y option to avoid confirmation.

To install a single package

$ sudo yum install nano

To install multiple packages

$ sudo yum install MariaDB-server MariaDB-client

Add the -y option with yum to install a package without your confirmation.

$ sudo yum install nano -y

Use the following command to install a package from a specific repository. In this case, we are installing the “htop” package from the EPEL repository.

$ sudo yum --disablerepo="*" --enablerepo=epel install htop

To install local rpm file, run the below command.

$ sudo yum localinstall /path/to/file.rpm

To install an rpm package directly from the URL, run the command below.

$ sudo yum localinstall https://xyz.com/file.rpm

4) How to Remove a Package or Packages on CentOS/RHEL/Oracle Linux Systems Using the yum Command

Use the “remove” or “erase” option to remove specific packages, which removes dependencies as well from the system.

In our case, we are going to remove the nano package from the system.

# yum remove nano -y

Alternatively, you can use the following command.

# yum erase nano -y

5) How to Check Package Updates Available on CentOS/RHEL/Oracle Linux Systems Using the yum Command

This command checks if any package updates are available on the system.

This command checks whether any updates to your system (It’s dry-run).

# yum check-update

Alternatively, you can use the command below to check the available update.

# yum list updates

The following command checks for updates to the specified package.

# yum check-update [Package_Name]
# yum check-update nano

6) How to Update a Package or Packages on CentOS/RHEL/Oracle Linux Systems Using the yum Command

It allows you to install available package updates on your system. Also, you can install specified package or group of packages, or a package to a specific version and more.

Run the below command to update all installed packages to the latest available version.

# yum update

Alternatively, you can use the below command. This will excludes “obsoletes” packages when run yum command.

# yum upgrade

It works the same as above, but it doesn’t actually install any updates (like it’s a dry run). This will return values in terms of the transaction. Also returns a list of the packages to be updated in list format.

  • N: Returns exit value of “N” (N-number of packages) if there are packages available for an update.
  • 0: Returns 0 if no packages are available for update.
  • 1: Returns 1 if an error occurred.
# yum check−update

Run the below command to update a given package or packages to the latest available version.

# yum upgrade [Package_Name]
# yum upgrade nano

Run the below command to upgrade a given package or packages to the specified versions.

# yum update [Package_Version]
# yum update nano-2.9.8-1

7) How to Check and Update Security Advisories on CentOS/RHEL/Oracle Linux Systems Using the yum Command

The below yum plugin extends yum to allow lists and updates only security related packages.

The below commands will display information about update advisories. This shows how many package updates are available for Security, Bug Fixes and Enhancement.

Run the command below to display the number of advisory types.

# yum updateinfo summary

Updates Information Summary: available
    1 Bugfix notice(s)

This command displays list of advisories.

# yum updateinfo list

To list all updates that are relevant to security.

$ sudo yum --security check-update

To upgrade packages that have security errata (upgrades to the latest available package).

$ sudo yum --security update

To get a list of all security advisories.

$ sudo yum updateinfo list all security
or
$ sudo yum updateinfo list all sec

To get a list of all enhancement packages.

$ sudo yum updateinfo list all enhancement

To get a list of all bugfixs packages.

$ sudo yum updateinfo list all bugfix

This command will give you detailed information about the given advisory ID.

# yum updateinfo info FEDORA-EPEL-2020-a062204588

Run the following command to install the given advisory.

$ sudo yum update --advisory=XYZ-2020-1001

Run the following command to install the given CVE.

$ sudo yum update --cve=CVE-2201-0123

8) How to List Installed Packages on CentOS/RHEL/Oracle Linux Systems Using the yum Command

The list options is used to list various information about available packages. You can customize the output according to your needs.

Run the below command to list all packages, present in the RPMDB, in a repo or in both.

# yum list
or
# yum list all

Run the below command to list only installed packages in RPMDB.

# yum list installed

Run the below command to list available packages from repos, excluding installed packages.

# yum list available

Run the command below to see if a given package is installed. If yes, it shows an output like the one below. Otherwise, it displays the following error message “Error: No matching packages to list”

# yum list installed httpd

Installed Packages
nano.x86_64                       2.3.1-10.el7                        @anaconda

To list packages installed on the system that are obsoleted.

# yum list obsoletes

Run the below command to list packages recently added into the repositories.

# yum list recent

Run the below command to list upgrades available for the installed packages.

# yum list updates

9) How to Search a Package on CentOS/RHEL/Oracle Linux Systems Using the yum Command

The search option lets you find a package when you don’t know the exact package.

It looks for package metadata for given keywords and summarizes the output based on it.

In our case, we’re going to look for the ftpd string and see what happens.

# yum search ftpd

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.hbcse.tifr.res.in
 * centos-sclo-rh: centos.hbcse.tifr.res.in
 * centos-sclo-sclo: centos.mirrors.estointernet.in
 * epel: epel.dionipe.id
 * extras: centos.hbcse.tifr.res.in
 * remi-safe: ftp.riken.jp
 * updates: centos.mirrors.estointernet.in
============================== N/S matched: ftpd ==============================
proftpd-devel.x86_64 : ProFTPD - Tools and header files for developers
proftpd-ldap.x86_64 : Module to add LDAP support to the ProFTPD FTP server
proftpd-mysql.x86_64 : Module to add MySQL support to the ProFTPD FTP server
proftpd-postgresql.x86_64 : Module to add PostgreSQL support to the ProFTPD FTP
                          : server
proftpd-sqlite.x86_64 : Module to add SQLite support to the ProFTPD FTP server
proftpd-utils.x86_64 : ProFTPD - Additional utilities
pure-ftpd-selinux.x86_64 : SELinux support for Pure-FTPD
vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
nordugrid-arc-gridftpd.x86_64 : ARC gridftp server
nordugrid-arc6-gridftpd.x86_64 : ARC gridftp server
perl-ftpd.noarch : Secure, extensible and configurable Perl FTP server
proftpd.x86_64 : Flexible, stable and highly-configurable FTP server
pure-ftpd.x86_64 : Lightweight, fast and secure FTP server
vsftpd.x86_64 : Very Secure Ftp Daemon

  Name and summary matches only, use "search all" for everything.

The above output shows matching string for ftpd keyword.

10) How to View Installed Package Information on CentOS/RHEL/Oracle Linux Systems Using the yum Command

If you would like to find brief information about installed and available packages, use the following command.

This command allows you to check detailed information about any packages available in repos. It shows you varies information about a package like Name, Arch, version, Release, Size, repo name, etc,.

# yum info vsftpd

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.hbcse.tifr.res.in
 * centos-sclo-rh: centos.hbcse.tifr.res.in
 * centos-sclo-sclo: centos.mirrors.estointernet.in
 * epel: epel.dionipe.id
 * extras: centos.hbcse.tifr.res.in
 * remi-safe: ftp.riken.jp
 * updates: centos.mirrors.estointernet.in
Available Packages
Name        : vsftpd
Arch        : x86_64
Version     : 3.0.2
Release     : 25.el7
Size        : 171 k
Repo        : base/7/x86_64
Summary     : Very Secure Ftp Daemon
URL         : https://security.appspot.com/vsftpd.html
License     : GPLv2 with exceptions
Description : vsftpd is a Very Secure FTP daemon. It was written completely
            : from scratch.

11) How to Use the “provides or whatprovides” Command

The yum prvoides command will find packages that provide the given file. This is useful if you want to find out which package (installed or not) provides this file.

For example, we all know about /etc/passwd file, and most of us do not know which package provides this file. Use the following command to find it.

# yum provides /etc/passwd
or
# yum whatprovides /etc/passwd

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.hbcse.tifr.res.in
 * centos-sclo-rh: centos.hbcse.tifr.res.in
 * centos-sclo-sclo: centos.mirrors.estointernet.in
 * epel: epel.dionipe.id
 * extras: centos.hbcse.tifr.res.in
 * remi-safe: ftp.riken.jp
 * updates: centos.mirrors.estointernet.in
setup-2.8.71-10.el7.noarch : A set of system configuration and setup files
Repo        : base
Matched from:
Filename    : /etc/passwd

setup-2.8.71-10.el7.noarch : A set of system configuration and setup files
Repo        : @anaconda
Matched from:
Filename    : /etc/passwd

12) How to Use the “makecache” Command

Makecache is used to download and make usable all the metadata for the currently enabled repository on your system.

# yum makecache

13) How to List Package Groups Available on CentOS/RHEL/Oracle Linux Systems Using the yum Command

A list of packages related to each other is grouped together in a group package. Run the following command to list the package groups available on your system.

# yum grouplist
or
# yum group list

14) How to View Summary of Groups Available on CentOS/RHEL/Oracle Linux Systems Using the yum Command

This display overview of how many groups are installed and available on your system.

# yum group summary

Available Environment Groups: 12
Available Groups: 21
Done

15) How to View a Specified Group Info on CentOS/RHEL/Oracle Linux Systems Using the yum Command

This command displays the list of packages available in this group.

Each group has three parts and the details are as follows:

  • Mandatory Packages
  • Default Packages
  • Optional Packages
# yum group info 'Development Tools'

16) How to Install a Package Group on CentOS/RHEL/Oracle Linux Systems Using the yum Command

Run the following command to install a package group.

In this case we are going to install “Development Tools” package group. The editors group has bundled with a lots of packages that are related to editor.

# yum group install 'Development Tools' -y
or
# yum groupinstall 'Development Tools' -y

17) How to Update a Package Group on CentOS/RHEL/Oracle Linux Systems Using the yum Command

Similarly run the following command to update package group to available latest version.

# yum group update 'Development Tools' -y
or
# yum groupupdate 'Development Tools' -y

18) How to Remove a Package Group on CentOS/RHEL/Oracle Linux Systems Using the yum Command

Use the below command to remove the given installed package group.

# yum group remove 'Development Tools'
or
# yum group erase 'Development Tools'

19) How to Clear Cached Data on CentOS/RHEL/Oracle Linux Systems Using the yum Command

By default yum command will cache data such as package and repository metadata to the “/var/cache/yum” directory when you perform varies yum operation. This cache can take up a lot space over the period of time. This will allow you to remove all cached data.

Run the below command to remove cache files generated from the repository metadata.

# yum clean dbcache

Run the below command to mark the repository metadata expired.

# yum clean expire-cache

Run the below command to remove repository metadata.

# yum clean metadata

Run the below command to remove any cached packages from the system.

# yum clean packages

Run the below command to remove any cached date from the local rpmdb.

# yum clean rpmdb

Run the below command to remove any cached plugins from the system.

# yum clean plugins

This command eoes all of the above action in one go.

# yum clean all

20) How to Download Package RPM File on CentOS/RHEL/Oracle Linux Systems Using the yum Command

Instead of installing a package on your computer using the “Yumdownloader” command you can easily download the given package .rpm file from the repository.

To do so, you need to install the “yum-utils” package.

# yum install yum-utils -y

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

# yumdownloader nano

21) How to Add New Repository on CentOS/RHEL/Oracle Linux Systems Using the yum Command

Every repositories commonly provide their own “.repo” file. To add a repository to your system, run the following command as root user.

# yum-config-manager --add-repo http://www.example.com/example.repo

Loaded plugins: product-id, refresh-packagekit, subscription-manager
adding repo from: http://www.example.com/example.repo
grabbing file http://www.example.com/example.repo to /etc/yum.repos.d/example.repo
example.repo                                             |  413 B     00:00
repo saved to /etc/yum.repos.d/example.repo

22) How to Exclude Specific Packages from Yum Update

You can use --exclude or -x switch with yum command to exclude specific packages from getting updated through yum command.

The below command will update all packages except kernel.

# yum update --exclude=kernel
or
# yum update -x 'kernel'

23) How to Configure Automatic Updates with yum-cron on RHEL/CentOS/Oracle Linux Systems

The yum-cron package allows you to enable automatic updates with the yum command, and customize it to suit your needs, such as performing a full system update or security update only.

It provides the required configuration for repository metadata updating, downloading and updating using cronjob.

To do so, install the yum-cron package.

# sudo yum install yum-cron
# systemctl enable yum-cron
# systemctl start yum-cron

For RHEL/CentOS 6, run the following command.

$ sudo chkconfig yum-cron on
$ sudo service yum-cron start

You can customize the yum command based on your needs by editing the file “/etc/yum/yum-cron.conf”.

# vi /etc/yum/yum-cron.conf

24) How to Print yum History on CentOS/RHEL/Oracle Linux Systems Using the yum Command

The yum history command allows the user to view what action has happened in past transactions. All transactions showed in a table.

# yum history

Loaded plugins: fastestmirror, langpacks
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    51 | -d 2 -y install httpd    | 2020-02-01 15:03 | Install        |    1   
    50 | -d 2 -y remove httpd     | 2020-02-01 15:01 | Erase          |    1   
    49 | -d 2 -y install httpd    | 2020-02-01 14:43 | Install        |    1   
    48 | -d 2 -y remove httpd     | 2020-02-01 14:41 | Erase          |    1   
    47 | -d 2 -y install httpd    | 2020-02-01 14:31 | Install        |    1   
    46 | -d 2 -y remove httpd     | 2020-02-01 14:29 | Erase          |    1   
    45 | -d 2 -y install httpd    | 2020-02-01 14:23 | Install        |    1   
    44 | -d 2 -y remove httpd     | 2020-02-01 14:21 | Erase          |    1   
    43 | -d 2 -y install httpd    | 2020-02-01 14:15 | Install        |    1   
    42 | -d 2 -y remove httpd     | 2020-02-01 14:13 | Erase          |    1   
    41 | -d 2 -y install httpd    | 2020-02-01 14:11 | Install        |    1   
    40 | -d 2 -y remove httpd     | 2020-02-01 14:06 | Erase          |    1   
    39 | -d 2 -y install httpd    | 2020-02-01 14:03 | Install        |    1   
    38 | -d 2 -y remove httpd     | 2020-02-01 14:00 | Erase          |    1   
    37 | -d 2 -y install httpd    | 2020-02-01 13:24 | Install        |    1   
    36 | -d 2 -y remove httpd     | 2020-02-01 13:23 | Erase          |    1   
    35 | -d 2 -y install httpd    | 2020-02-01 13:17 | Install        |    1   
    34 | -d 2 -y remove httpd     | 2020-02-01 13:13 | Erase          |    1   
    33 | -d 2 -y install httpd    | 2020-02-01 13:11 | Install        |    1   
    32 | -d 2 -y remove httpd     | 2020-02-01 12:18 | Erase          |    1   
history list

Alternatively, you can get the same result using the following command.

# yum history list

It shows you detailed information about the given transactions. When no transaction is specified, describe what happened during the latest transaction.

# yum history info

Loaded plugins: fastestmirror, langpacks
Transaction ID : 51
Begin time     : Sat Feb  1 15:03:52 2020
Begin rpmdb    : 1429:15e65dbd542cd0e1c44c3ea66b16df1af52479fa
End time       :            15:03:54 2020 (2 seconds)
End rpmdb      : 1430:8106175a0e145cf7f330151e520fcfcd737f56fe
User           : 2daygeek 
Return-Code    : Success
Command Line   : -d 2 -y install httpd
Transaction performed with:
    Installed     rpm-4.11.3-35.el7.x86_64                      @anaconda
    Installed     yum-3.4.3-161.el7.centos.noarch               @anaconda
    Installed     yum-metadata-parser-1.1.4-10.el7.x86_64       @anaconda
    Installed     yum-plugin-fastestmirror-1.1.31-50.el7.noarch @anaconda
Packages Altered:
    Install httpd-2.4.6-90.el7.centos.x86_64 @base
history info

Run the following command to view the detailed information about the given ID transactions.

# yum history info 34

Loaded plugins: fastestmirror, langpacks
Transaction ID : 34
Begin time     : Sat Feb  1 13:13:50 2020
Begin rpmdb    : 1430:8106175a0e145cf7f330151e520fcfcd737f56fe
End time       :            13:13:52 2020 (2 seconds)
End rpmdb      : 1429:15e65dbd542cd0e1c44c3ea66b16df1af52479fa
User           : 2daygeek 
Return-Code    : Success
Command Line   : -d 2 -y remove httpd
Transaction performed with:
    Installed     rpm-4.11.3-35.el7.x86_64                      @anaconda
    Installed     yum-3.4.3-161.el7.centos.noarch               @anaconda
    Installed     yum-plugin-fastestmirror-1.1.31-50.el7.noarch @anaconda
Packages Altered:
    Erase httpd-2.4.6-90.el7.centos.x86_64 @base
history info

Repeat the same action for the specified transaction ID.

# yum history redo 3

Perform the opposite operation to all operations performed in the specified transaction.

# yum history undo 3

Undo all transactions performed after the specified transaction.

# yum history rollback 7

25) Visit the yum Man Page

We have added all possible options in this article but if you are looking for any other option, which is not listed in this article visit man page.

# yum -help
or
# man yum

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *