DNF is a package manager that is used on RHEL-based systems. It checks and updates packages on the system when the dnf update command is run. But there is an alternative option to upgrade packages regularly and automatically based on systemd timers, cron jobs, and other similar tools. This package is called DNF Automatic that is usually controlled by a configuration file or function-specific timer units.
The DNF Automatic tool synchronizes package metadata as needed, checks for updates available, and performs the actions of exiting, downloading the updates or downloading and installing the updates. The outcome of the process is communicated via standard output, an email, or MOTD messages.
This guide will show you how to install DNF Automatic and enable automatic updates on CentOS 9|AlmaLinux 9|RHEL 9 systems.
Install DNF Automatic on CentOS 9|AlmaLinux 9|RHEL 9
To install the DNF Automatic package, use the following command.
$ sudo dnf install dnf-automatic
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
dnf-automatic noarch 4.10.0-5.el9_0 rhel-9-for-x86_64-baseos-rpms 44 k
Transaction Summary
================================================================================
Check for the package to verify successful installation
$ sudo rpm -qi dnf-automatic
Name : dnf-automatic
Version : 4.10.0
Release : 5.el9_0
Architecture: noarch
Install Date: Mon 20 Jun 2022 08:49:21 PM EAT
Group : Unspecified
Size : 52992
License : GPLv2+
Signature : RSA/SHA256, Mon 21 Mar 2022 08:26:03 PM EAT, Key ID 199e2f91fd431d51
Source RPM : dnf-4.10.0-5.el9_0.src.rpm
Build Date : Mon 21 Mar 2022 01:08:17 PM EAT
Build Host : x86-vm-56.build.eng.bos.redhat.com
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor : Red Hat, Inc.
URL : https://github.com/rpm-software-management/dnf
....
Configure DNF Automatic on CentOS 9|AlmaLinux 9|RHEL 9
The DNF Automatic configuration file is located at /etc/dnf/automatic.conf
. The configuration file has different sections that can be edited to define its behavior.
These include;
- The [commands] sections
It sets the mode of operation for the program by using Boolean Variables of yes and no. - The [emitters] section
These define how the results of DNF Automatic are reported. - The [command] section
It is different from the first one but defines the variables used in the message body - The [command_email] section
It contains variables for external commands used to send an email. - The [email] section
It is the email emitter configuration. - The [base] section
It can be used to override settings on the main DNF configuration file.
All these sections have their own set of variables that can be edited to define how DNF Automatic will behave. As of installation, the config file has default values that can be changed.
To edit the file, for example, to set the DNF Automatic package to install updates, I would edit the configuration file.
sudo vi /etc/dnf/automatic.conf
Then find the section for command and set the apply updates variable to yes. You can also change the emitters section to select how to report results.
[commands]
apply_updates = yes
[emitters]
emit_via = motd
Save and exit the file. Results that are emitted via MOTD are found in the /etc/motd file.
Enabling DNF Automatic on CentOS 9|AlmaLinux 9|RHEL 9
To use DNF Automatic, you should start and enable a specific systemd timer unit. There are four available timer units;
- dnf-automatic
- dnf-automatic-notifyonly
- dnf-automatic-download
- dnf-automatic-install
dnf-automatic
This behaves as the configuration file specifies. To enable this timer unit use the following command.
sudo systemctl enable --now dnf-automatic.timer
Verify the status of the timer.
$ systemctl status dnf-automatic.timer
● dnf-automatic.timer - dnf-automatic timer
Loaded: loaded (/usr/lib/systemd/system/dnf-automatic.timer; enabled; vend>
Active: active (waiting) since Mon 2022-06-20 21:03:42 EAT; 48s ago
Until: Mon 2022-06-20 21:03:42 EAT; 48s ago
Trigger: Tue 2022-06-21 06:45:50 EAT; 9h left
Triggers: ● dnf-automatic.service
dnf-automatic-notifyonly
This will override the default configuration file and only notify you of the available updates by keeping the repository cache up-to-date. To enable this timer unit, use the following command.
sudo systemctl enable --now dnf-automatic-notifyonly.timer
Verify the status of the timer.
$ systemctl status dnf-automatic-notifyonly.timer
● dnf-automatic-notifyonly.timer - dnf-automatic-notifyonly timer
Loaded: loaded (/usr/lib/systemd/system/dnf-automatic-notifyonly.timer; en>
Active: active (waiting) since Mon 2022-06-20 21:09:00 EAT; 16s ago
Until: Mon 2022-06-20 21:09:00 EAT; 16s ago
Trigger: Tue 2022-06-21 06:27:17 EAT; 9h left
Triggers: ● dnf-automatic-notifyonly.service
dnf-automatic-download
This will also override the main configuration file and only download the available updates but not install them. To enable this timer unit, use the following command.
sudo systemctl enable --now dnf-automatic-download.timer
Verify the status of the timer.
$ systemctl status dnf-automatic-download.timer
● dnf-automatic-download.timer - dnf-automatic-download timer
Loaded: loaded (/usr/lib/systemd/system/dnf-automatic-download.timer; enab>
Active: active (waiting) since Mon 2022-06-20 21:10:16 EAT; 11s ago
Until: Mon 2022-06-20 21:10:16 EAT; 11s ago
Trigger: Tue 2022-06-21 06:49:30 EAT; 9h left
Triggers: ● dnf-automatic-download.service
dnf-automatic-install
This will also override the default configuration file, then download and install the available package updates. To enable this timer unit, use the following command.
sudo systemctl enable --now dnf-automatic-install.timer
To verify the status of the timer
$ systemctl status dnf-automatic-install.timer
● dnf-automatic-install.timer - dnf-automatic-install timer
Loaded: loaded (/usr/lib/systemd/system/dnf-automatic-install.timer; enabl>
Active: active (waiting) since Mon 2022-06-20 21:11:05 EAT; 13s ago
Until: Mon 2022-06-20 21:11:05 EAT; 13s ago
Trigger: Tue 2022-06-21 06:18:28 EAT; 9h left
Triggers: ● dnf-automatic-install.service
To list enabled timer units, use the following command. The –all option also lists timers that are loaded but inactive.
sudo systemctl list-timers *dnf-* --all
Conclusion
This guide has shown you how to install DNF Automatic and enable automatic updates on CentOS 9|AlmaLinux 9|RHEL 9 systems. DNF Automatic is an alternative command-line interface to dnf update with special features that facilitate regular and automatic updates. More configuration options can be found at DNF Automatic Configuration.
More guides:
- Install Docker Compose on CentOS 9 / AlmaLinux 9 / RHEL 9
- Install MongoDB on CentOS 9 / AlmaLinux 9 / RHEL 9
- Using Beets Music Media System on Ubuntu / Debian