Managing software with Yum and DNF
Understanding how to manage software packages is a fundamental skill for administering Linux servers. On Red Hat-based distributions, such as AlmaLinux and Rocky Linux, the primary tools for this are the package managers Yum and its successor, DNF.
It’s important to note that while you may be familiar with Yum, it has been replaced by DNF in Red Hat 8 and its derivatives. Fortunately, DNF is essentially the same thing as Yum, and the commands you use with Yum will also work with DNF.
For a quick reference, a helpful Yum cheat sheet is available from Red Hat.
https://access.redhat.com/articles/yum-cheat-sheet
Key configuration files
The main configuration file for the package manager (Yum/DNF) is located at: /etc/yum.conf
Understanding repositories
Software packages (specifically, RPM files) are obtained from repositories, often shortened to “repos”. These repositories are configured using files found in the following directory: /etc/yum.repos.d/
Any file in this directory ending in .repo will be read and processed by the package manager.
Within a .repo file, several settings are crucial for defining a repository:
- **name=**: Specifies a human-readable name for the repository.
- **baseurl=**: Defines the URL where the packages for this repository are stored.
- **enabled=**: Controls whether the repository is active (1) or inactive (0).
Essential commands
Here are some common commands for managing packages:
To view information about installed or available packages, including versions and architectures:
yum list $packageTo search specifically for available packages matching a pattern or a string:
yum list available ea*php70* yum search $stringTo install a new software package onto your system:
yum install $packageTo update a specific package to its latest available version:
yum update $packageTo update all installed packages on your system to their latest versions:
yum updateTo remove a package from your system. Please be aware that yum remove removes dependencies by default. Using this command carelessly could potentially damage the operating system. The command will ask for confirmation before proceeding. If you see a long list of packages scheduled for removal, it is strongly recommended to say ‘no’ and seek an alternative method to achieve your goal.
yum remove $packageMore advanced operations
Beyond basic installation and removal, Yum and DNF offer more powerful tools:
To determine which package a specific file belongs to:
yum provides <path_to_file>For example, to find the package for the less command:
yum provides ``which less``If you know a filename but not its full path, you can use wildcards:
yum provides *filename*For example, to find packages containing libm.so.6:
yum provides *libm.so.6To clear the package manager’s local cache of repository metadata and packages:
yum clean allTo view the list of dependencies required by a particular package:
yum deplist $packageTo install an older version of a package that is currently installed:
yum downgrade $packageTo display detailed information about a package, such as description, version, release, size, and repository:
yum info $packageTo install a package file that you have downloaded to your server locally:
yum localinstall $packageTo reinstall a package that is already installed. Note that this command only works if your system is currently up to date.
yum reinstall $packageTo see a list of all repositories currently configured and enabled on your system:
yum repolistTo manage past package manager actions using the history feature. First, you can list previous transactions to find the one you want to affect:
yum history listThen, you can attempt to undo a specific transaction using its number. Be extremely careful to select the correct transaction number, as selecting the wrong one can potentially cause further system issues.
yum history undo $transaction_numberUsing these commands and understanding the repository configuration will help you effectively manage software on your Red Hat-based systems using either Yum or DNF.