In this tutorial, we will explore on how to enable updates automatically with dnf-automatic in RHEL, AlmaLinux and Rocky Linux. Every administrator has to do operating system upgrades on a daily basis. The issue is that those updates may occasionally be neglected in favor of more pressing matters. What, though, is more crucial than updating and protecting your operating systems? Sure, there are always essential concerns that constantly arise that you must deal with. You should never let such problems stop you from making sure your operating systems are up to date, though.
However, given your hectic schedule, you should at least make the effort to configure automated updates so that they occur on a regular basis. You don’t want to pass on critical security updates, improved speed, and fresh features, after all. Hence we will see on how we can install the utility called “dnf-automatic” to perform these updates.
Introduction
An alternative to the dnf upgrade command is dnf-automatic, which can be run automatically and on a regular basis using cron jobs, systemd timers, and other similar programs.
After making any necessary synchronizations with the package metadata, it looks for any updates for your RHEL-based computers. The dnf-automatic command either downloads and installs the packages, downloads and updates the packages, or just exits according on the configuration file parameters.
The operation of dnf-automatic is normally regulated by the configuration file (dnf-automatic.timer) or function-specific timer units as stated below.
- dnf-automatic-notifyonly : This option only alerts users when updates are available.
- dnf-automatic-download : This feature merely downloads updates without installing them.
- dnf-automatic-install : Package updates are downloaded and installed automatically with
Pre-requisite
A Rocky Linux 8 or 9 server and a non-root user with sudo privileges. You can learn more about how to set up a user with these privileges in our How to install Rocky Linux guide. You can also chose any Red Hat Linux or any of it fork such as Alma Linux.
Required Package Installation
Let us start with the installation of the packages for the program which is available in the default repositories of RHEL and its clone
$ sudo dnf install dnf-automatic
Configuring Automatic updates
Edit the default configuration for the dnf-automatic using any of your editor
$ sudo vi /etc/dnf/automatic.conf
Make sure your file adjusts the below settings. Find the below 3 lines in the file and adjust accordingly.
upgrade_type = default
download_updates = yes
apply_updates = no
dnf will automatically download all updates in accordance with the setup mentioned above, but it won’t install them. Just set the apply-updates setting’s value to yes if you want the updates to be applied automatically. The option for automatic updates is turned off by default.
Enable the timer unit
$ sudo systemctl enable --now dnf-automatic.timer
At this point you have made sure that the updates are downloaded and installed automatically when they are available. The default timer is set up, so updates will be applied at 6 a.m. every day. If that’s not a good time for your organization, you can change it by opening the dnf-automatic.timer file with the command:
sudo vi /etc/systemd/system/timers.target.wants/dnf-automatic.timer
In the above file you can check for the line starting with below
OnCalendar=*-*-*
Lets say you want to run the updates at 2 AM everyday so the line should look like –
OnCalendar=*-*-* 02:00
Additionally, you may want to enable dnf-automatic to run at a new time every day and modify the randomized delay, which is currently set at 60 minutes. Modify the line to make that inactive:
RandomizedDelaySec = 60m
To
RandomizedDelaySec = 0m
Now save the file and close it followed by a daemon reload
sudo systemctl daemon-reload
Conclusion
Throughout this blog, you have examined various approaches to automatically upgrade your RHEL based Linux servers. A few of the subtleties of managing server reboots, package repositories, and kernel updates were also covered. Nearly all production configurations are built upon these principles, which are all crucial aspects of DevOps and working with servers in general. For more details you can also visit Red Hat Linux – Automating software updates