- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Check and Install Updates On CentOS and RHEL?
Introduction
Keeping your system up to date is essential for maintaining the security, stability, and performance of your computer. Cybercriminals are always looking for vulnerabilities in operating systems and software to exploit, putting you at risk of data breaches, identity theft, and other cyber threats. Moreover, software updates usually include bug fixes and enhancements that improve the functionality and compatibility of your applications with other programs.
Therefore, it is crucial to regularly check for updates on CentOS/RHEL and apply them promptly. In this guide, you will learn how to use Yum Package Manager and DNF Package Manager - two popular package managers on CentOS/RHEL distributions -to manage updates effectively.
Checking for Updates
Keeping your system up to date is crucial for security and stability. Checking for updates is the first step in this process. CentOS and RHEL users can check for available updates using two package managers - Yum and DNF.
Using Yum Package Manager
Yum (Yellowdog Updater Modified) is a command-line package manager that automatically resolves dependencies and retrieves the packages from repositories. It was the default package manager in CentOS 6 and earlier versions but has been replaced by DNF since CentOS 8. The command to check for updates with Yum is −
yum check-update
This command will query the configured repositories on your system and list all available updates, grouped by their respective packages. The output displays relevant details such as package name, version, architecture, repository name, size, and update status.
You may interpret the output as follows −
The "Installed" column indicates whether you have an earlier version of the package installed or not.
The "Available" column contains information about new versions of the packages available from any of the enabled repositories on your system.
You should pay attention to any updates with a "security" tag in their description as they usually contain critical bug fixes or security patches.
Using DNF Package Manager
DNF (Dandified YUM) is a next-generation fork of Yum that uses modern libraries and data structures to improve performance, dependency resolution, parallel downloads, and transactional errors handling. It became the default package manager in CentOS 8 onwards but can be installed on earlier versions too. To check for available updates using DNF, run this command −
dnf check-update
The output of this command is similar to Yum's, except the package version number has a colon appended to it. The colon indicates the epoch value, which is only relevant when comparing package versions across different releases since it represents the versioning scheme.
You can interpret the output of dnf check-update as follows −
The "Repo" column displays which repository provided each update.
The "Package" column lists all the packages with updates available.
The "Upgrade Type" column specifies whether an update provides new functionality or bug fixes only.
Overall, both Yum and DNF provide a reliable way to check for available updates on your CentOS or RHEL system. Next, we'll look at how to install these updates.
Installing Updates
Using Yum Package Manager
Once you have checked for updates and identified which packages need to be updated, it is time to install them. Installing updates on CentOS or RHEL using the Yum package manager is a simple process.
To install updates with Yum, use the following command −
$ sudo yum update
This command will prompt you to confirm that you want to download and install the available updates. Once you confirm, Yum will begin downloading and installing the updates for your system.
The output of this command includes detailed information about each package that is being downloaded and installed. The output includes the package name, version number, file size, and a progress bar indicating how much of each package has been downloaded.
Using DNF Package Manager
DNF is another popular package manager used on CentOS and RHEL systems. To install updates using DNF, use the following command −
$ sudo dnf update
This command will display a list of packages that need to be updated along with their version numbers. You will be prompted to enter 'y' or 'n' to proceed with updating the listed packages or not respectively.
The output of this command includes detailed information about each package that is being downloaded and installed similar to Yum's output. The output includes information such as the name of the package being updated, its current version number compared against its available version number from yum repositories if any as well as other information like file sizes etc.
Setting Up Automatic Updates
Explanation on Why You Need Automatic Updates
Regularly updating your operating system is crucial to keep it secure and running efficiently. However, manually checking for updates and installing them can be a time-consuming process. This is where automatic updates come in.
By setting up automatic updates, you ensure that your CentOS or RHEL system receives all the necessary patches and upgrades without any intervention from you. This saves you time while ensuring that your system remains secure and up-to-date.
How to Set Up Automatic Updates Using Yum-cron Package
The yum-cron package provides a simple way to set up automatic updates on CentOS and RHEL systems using Yum package manager. To install the package, run the following command −
sudo yum install yum-cron
Once installed, edit the configuration file `/etc/yum/yum-cron.conf` using a text editor such as nano or vim. Modify the following options to enable automatic updates −
apply_updates = yes download_updates = yes
You can also specify when these updates should occur by modifying the following option −
update_cmd = default
Save and close the file when done. Start and enable the `yum-cron` service with the following commands − ```
sudo systemctl start yum-cron sudo systemctl enable yum-cron
How to Set Up Automatic Updates Using Dnf-automatic Package
The dnf-automatic package provides a similar way of setting up automatic updates on CentOS and RHEL systems using DNF package manager. To install this package, run this command −
sudo dnf install -y dnf-automatic
After successful installation of dnf-automatic service open its configuration file : /etc/dnf/automatic.conf.
Here are some changes need to be made in configuration file.
[commands] # what commands to use for the update process upgrade_type = default auto_upgrade = yes [emitters] # how to send out email notifications email_to = root system_name = None
There is one more file that needs to be modified and that is timer unit of dnf-automatic.
The timer unit defines when the dnf-automatic service will run and implement updates. Open this file /usr/lib/systemd/system/dnf-automatic.timer with vim editor or any other text editor you are comfortable with.
[Unit] Description=DNF automatic update timer [Timer] OnCalendar=daily RandomizedDelaySec=1h Persistent=true [Install] WantedBy=timers.target
Save and exit the file. Then Enable the timber by running this command −
sudo systemctl enable --now dnf-automatic.timer sudo systemctl start dnf-automatic-install.timer
Conclusion
Regularly updating your CentOS or RHEL system is essential for ensuring its security and optimal performance. This guide has shown you how to check for updates using both Yum and DNF package managers, as well as how to set up automatic updates using yum-cron or dnf-automatic packages. With these tools, you can automate the update process, save time, and ensure that your system stays up-to-date without any manual intervention needed.