Show Table of Contents
9.7. Automatically Refreshing Package Database and Downloading Updates with Yum-cron
The
yum-cron service checks and downloads package updates automatically. The cron jobs provided by the yum-cron service are active immediately after installation of the yum-cron package. The yum-cron service can also automatically install downloaded updates.
With default settings, the
yum-cron service:
- Updates the metadata in the yum cache once per hour.
- Downloads pending package updates to the yum cache once per day. If new packages are available in the repository, an email is sent. See chapter Section 9.7.2, “Setting up Optional Email Notifications” for more information.
The
yum-cron service has two configuration files:
/etc/yum/yum-cron.conf- For daily tasks.
/etc/yum/yum-cron-hourly.conf- For hourly tasks.
9.7.1. Enabling Automatic Installation of Updates
To enable automatic installation of downloaded updates, edit the daily configuration file for daily installation or the hourly configuration file for hourly installation by setting the
apply_updates option as follows:
apply_updates = yes
9.7.2. Setting up Optional Email Notifications
By default, the
yum-cron service uses cron to send emails containing an output of the executed command. This email is sent according to cron configuration, typically to the local superuser and stored in the /var/spool/mail/root file.
You can use specific email configuration different from the settings which affect all
cron jobs. However, this email configuration does not support TLS and overall email built-in logic is very basic.
To enable
yum-cron built-in email notifications:
- Open selected
yum-cronconfiguration file:/etc/yum/yum-cron.conf- For daily tasks.
/etc/yum/yum-cron-hourly.conf- For hourly tasks.
- In the
[emitters]section, set the following option:emit_via = email
- Set the
email_from,email_to,email_hostoptions as required
9.7.3. Enabling or Disabling Specific Repositories
The
yum-cron does not support specific configuration of repositories. As a workaround for enabling or disabling specific repositories for yum-cron but not for yum in general follow the steps bellow:
- Create an empty repository configuration directory anywhere on the system.
- Copy all configuration files from the
/etc/yum.repos.d/directory to this newly created directory. - In the respective
.repoconfiguration file within the/etc/yum.repos.d/, set theenabledoption as follows:enabled = 1- To enable the repository.
enabled = 0- To disable the repository.
- Add the following option, which points to the newly created repository directory, at the end of the selected
yum-cronconfiguration file:reposdir=/path/to/new/reposdir
9.7.4. Testing Yum-cron Settings
To test
yum-cron settings without waiting for the next scheduled yum-cron task:
- Open selected
yum-cronconfiguration file:/etc/yum/yum-cron.conf- For daily tasks.
/etc/yum/yum-cron-hourly.conf- For hourly tasks.
- Set the
random_sleepoption in the selected configuration file as follows:random_sleep = 0
- Run the configuration files:
# yum-cron /etc/yum/yum-cron.conf # yum-cron /etc/yum/yum-cron-hourly.conf
9.7.5. Disabling Yum-cron messages
The
yum-cron messages cannot be entirely disabled, but can be limited to messages with critical priority only. To limit the messages:
- Open selected
yum-cronconfiguration file:/etc/yum/yum-cron.conf- For daily tasks.
/etc/yum/yum-cron-hourly.conf- For hourly tasks.
- Set the following option in the
[base]section of the configuration file:debuglevel = -4
9.7.6. Automatically Cleaning Packages
The
yum-cron service does not support any configuration option for removing packages similar to the yum clean all command. To clean packages automatically, you can create a cron job as an executable shell script:
- Create a shell script in the
/etc/cron.daily/directory containing:#!/bin/sh yum clean all
- Make the script executable:
# chmod +x /etc/cron.daily/script-name.sh

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.