The yum command in Linux – A Cheat sheet

Yum Command

Every Linux distribution has a command line application called as package manager. Its main job is to take care of dependencies and install them whenever you try to install a new software and make sure that the installed dependencies do not conflict with other software programs which are already present on your system. Red Hat Enterprise Linux and the Linux operating systems which base themselves on it, basically use the RPM package management, and these RPM files are managed either by YUM (old) or using the DNF command.

OpenSUSE also uses the RPM package management, but it utilizes Zypper rather than DNF or YUM. In this article, we will learn more about the YUM package manager, learn how to install a particular package, remove certain packages from the system as well as see its most common use cases.

Yum: The package management application

YUM command (Yellowdog Updater Modified) is the traditional package management tool for Red Hat based systems such as Cent OS, Rocky Linux, Alma Linux etc. It is present in almost every Red Hat based distro, but isn’t the default in many of them now, even when It has been replaced by the newer DNF (dandified yum) command on Fedora, which is considered as upstream to RHEL. We have a separate article on DNF Linux package management software as well.

Yum – Basic Usage on Linux

The general syntax of YUM command is

yum [options] <command> [<args>...]

Available commands include install, search, query, etc. args can be a package’s name, a group name, or subcommand(s) specific to the ‘command’.

Note: To install and remove packages, you need to have sudo privileges. Since I am already root (which is not a great idea but works for the purpose of demonstration), I won’t be prepending any command with sudo. But keep in your mind that you must prepend sudo while installing and removing packages.

Note: On modern systems (CentOS 8 specifically) /usr/bin/yum is just a symlink to dnf. So, running yum eventually runs dnf.
This doesn’t cause a problem, as dnf has almost the same syntax as yum.

Managing packages in RPM based systems

Let’s now see how we can use the yum command to install/remove/query packages on our Red Hat based system.

1. Search and Install the package using Yum command

Let’s install Syncthing – the file-syncing application using this package manager. But you may not know the exact name of the package. It’s better to search for the package first. You can use the search command of YUM for searching packages. This will list all the packages that match with your query.

yum search syncthing
Yum Install Syncthing
Searching Syncthing will list all the available packages

In our case, the package name is also syncthing. Once you know the exact package name, you can use the install command to install the latest version of the package.

yum install syncthing
Yum Install Syncthing 1
Installing Syncthing

2. List information about a software package

To list more information about a package, use the info command of YUM.

Yum Info
YUM Info Syncthing

3. List all installed packages using yum

To see the list of installed packages that are available in your system, you can use the list installed sub-command of YUM.

yum list installed
Yum List Installed
YUM List Installed

Combined with the grep command, you can search whether a particular package is installed or not as follows:

yum list installed | grep vim
Yum List Installed 1
YUM List Installed Vim

If it didn’t produce any output, it means that the package is not installed. In that case, you can install the package.

4. Remove a package

To remove a specified package, use the remove command of YUM.

yum remove syncthing
Yum Remove
YUM Remove

To remove all unneeded packages that were originally installed as dependencies, use the autoremove command

yum autoremove
Yum Autoremove
YUM Autoremove

5. Upgrade a package using the yum command

On Debian based systems, sudo apt upgrade is used to install latest updates to the system. On RHEL, however, to upgrade all the packages that can be upgraded, use the upgrade command

yum upgrade
Yum Upgrade
Upgrading packages

You can also utilize yum update instead of upgrade in the above command, as the upgrade sub-command usually removes all the obsolete packages, which may be dangerous if the obsolete packages are necessary for your work environment.

sudo yum update

To upgrade a specific package, just add the name of the package, for example:

yum upgrade nftables
Yum Upgrade Nftables
YUM Upgrade Nftables

6. Reinstalling a particular package

Let’s say you are facing an error while using any application/CLI tool, and you want to see if reinstallation helps. In that case, you can use the following command:

yum reinstall neofetch
Reinstalling Packages
Reinstalling Packages

As you can see, we have successfully reinstalled the command neofetch which was already installed on the system using yum from the command line.

7. Search and Install package groups

Package groups are just multiple packages under a single name. These packages groups can be a whole server GUI, Security Tools, Administration Tools, etc. To see the list of available groups, you can use the group list command of YUM.

yum group list
Yum Group
YUM Group List

To know which packages are there in a group package, just use the group infocommand and give the name of the package. For “Security Tools” package, type

yum group info "Security Tools"

Note: You need to enclose the Group Package Name, which has multiple words in quotes(” “).
Even if the Group package name is a single word, it is recommended that you use quotes.

Yum Groupinfo
YUM Group Info

Let’s install the Security Tools Group package using the group install command.

yum group install "Security Tools"
Yum Group Install
Installing multiple packages by doing a group install

8. List enabled or available package repositories

To list all the available yum repositories, type

yum repolist all
Yum Repolist
Listing available repolist

To list all the enabled repositories, type

yum repolist enabled
Yum Repolist Enabled
Listing only enabled repolist

9. List dependencies of a package

To list the dependencies of a package, use the deplist command.

yum deplist syncthing
Yum Deplist
YUM Deplist

10. View history of installation/removal of packages

Sometimes, viewing your YUM history is a good idea, especially if you want to repeat the installations on a different system. History can be viewed using the history command of YUM.

Yum History
Looking at the history of this command

Note that you may want to clear the DNF/YUM cache from time to time as they begin to acquire more and more disk space over time.

Conclusion: A predecessor to the DNF command

DNF, which is the successor of this command, has a lot of similar commands as well as a configuration file which allows you to configure a lot of things in advanced, so you do not have to use the sub-commands. You can also learn more about DNF from our guide. You can also bookmark this page if you like the yum command cheat sheet for red hat enterprise Linux, and it’s derivative Linux distributions.


RedHat documentation of Yum Command