YUM (Yellowdog Updater, Modified)[1] is a free and powerful
package manager for RPM-based Linux distributions[2]. It was initially
developed to manage packages on the RHEL but now works in all
RPM-based systems, including CentOS, Fedora, Scientific Linux, and
Oracle Linux. It has become the de-facto tool for installing and
maintaining Linux packages on these systems due to its rich feature
set and easy to use parameters. No matter whether you’re a sysadmin
managing your system remotely or an everyday user, you can use yum
commands to locate specific packages, install them, or remove them
at ease.

YUM Commands for RPM-Based
Distributions


Our editors have selected 50 widely used yum commands for admins
and general users in this guide. Although this guide focuses
primarily on RHEL and CentOS, these commands will work the same for
all systems using RPM. We suggest readers go over them one by one
and bookmark this guide for future references.

1. Installing a
Package


One of the primary usages of a package manager like yum is
installing packages on your Linux or BSD system[3]. Luckily, yum makes it
very easy to install packages.

$ sudo yum install PACKAGE-NAME 
$ sudo yum install firefox

Yum will search the package in its repositories and resolve all
dependency issues for you itself. It will display information like
the repository name where the package is available and its size.
Simply enter Y in the confirmation prompt to start
the installation.

$ sudo yum -y install firefox

The above command will not ask for confirmation and install the
firefox package at one go. It’s a good way to automate your system
management.

yum command for package installation

2. Removing a
Package


Admins often need to remove obsolete packages to keep their
system fresh. You can use the following command to remove an
already installed package from your system.

$ sudo yum remove PACKAGE-NAME 
$ sudo yum remove firefox

This command will also ask for user confirmation as seen
earlier. You can either enter Y to carry on the
package removal process or use the below command to skip this step
altogether.

$ sudo yum -y remove firefox

3. Updating a
Package


Open source packages keep rolling out newer releases for
improving performance and tackling bugs. To update an already
installed RPM package, use the following command in your Linux terminal[4].

$ sudo yum update PACKAGE-NAME 
$ sudo yum update firefox

This will look for any latest updates and if available, will ask
the user for confirmation on whether to install the new release or
not. Add the -y option after yum if you want to
skip this prompt or are running this command from within Linux shell scripts[5].

$ sudo yum -y update firefox

4. Listing Package
Information


Admins should have a clear understanding of all the installed
packages in their system. Yum makes this very easy by exposing the
list option. See the below command to learn how this works

$ sudo yum list firefox

When you run the above command, it will display the version of
firefox installed in your machine and its source architecture. If
you don’t have firefox installed, it will display the available
packages for this web browser alongside the version
information.

5. Finding a Package


Searching is an essential feature of Linux package managers. It
allows users to locate packages without knowing their specific name
beforehand. Yum makes this task very easy as you will see in the
next command.

$ sudo yum search PACKAGE-NAME 
$ sudo yum search httpd

This command will search for all packages that contain the word
httpd‘ in them. It will display the results based
on three criteria. The first is the exact name match, then name &
summary match, and finally summary match. Yum will also show short
descriptions to help users easily locate the one they want.

6. Displaying Package
Information


You can find a lot of information about a package by using the
info sub-command of yum. This is essential for making sure you’re
not installing any harmful application in your workstation or
remote servers.

$ sudo yum info PACKAGE-NAME
$ sudo yum info firefox

The above command will show all relevant information about the
firefox package in your terminal. It will contain version
information as well as the size of the package, release
information, licensing, and a short description of the firefox
package.

7. Displaying all Installed
Packages


You can easily display all the packages installed in your
RPM-based system by using the following simple yum command.

$ sudo yum list installed
$ sudo yum list installed | less

Both of the above commands will display a list of all currently
installed packages. However, the second command is more flexible
since it allows users to scroll through the list using the
PageUp and PageDown buttons of
their keyboard.

view installed packages

8. Checking if a Package is
Already Installed


We can combine the above command with the Linux grep command[6]
to check whether a specific application is already installed in our
machine or not. This saves us from scrolling through the entire
list of packages.

$ sudo yum list installed | grep curl

You can also use the awk command in Linux[7]
to perform this task, as shown below. Check our previous guide on
awk to learn more about its workings.

$ sudo yum list installed | awk '/curl/ {print}'

9. Displaying all Available and
Installed Packages


The list sub-command also allows us to view all the available
and installed packages for our system. This is useful in a number
of situations.

$ sudo yum list | less

This will first show all the packages already installed in your
system, followed by a list of all available packages. Use the
followed command if you only wish to see the available
packages.

$ sudo yum list available | less

10. Displaying all Available
Updates


Admins should always try to keep their system up to date by
installing the most recent packages. The following simple command
makes this very easy for RPM-based systems.

$ sudo yum list updates | less

This command will display all packages in your system that has
updates available. You can now upgrade them to keep get rid of
outdated packages and replace them with their latest alternatives
at ease.

11. Displaying Available Updates
for Your System


The above command will show all the packages in the yum
repositories that have updates available to them. However, in most
cases, your system will only have a select number of these packages
installed. So, usually, you don’t need to list available updates
for all repository packages.

$ sudo yum check-update

The above command show will only the updates that are available
for your installed packages. Thus, it is more than enough for most
real-life scenarios.

12. Updating the
System


The yum update command allows users to update their RPM-based
systems very easily. The below command will download and install
all the latest updates for your installed packages as well as any
recent security patches.

$ sudo yum update

It will display the packages that are going to be installed
alongside their version and size information. Since this command
asks the users for confirmation, you will need to manually enter
the keystroke Y. Use the following command if you
want to avoid this.

$ sudo yum -y update

13. Applying Security Patches
Only


If you are a system admin responsible for managing remote
RHEL or CentOS servers[8], chances are you’ll
often want to leave the user-space programs alone and only install
security updates. Luckily, you can use the below command to do just
this.

$ sudo yum update --security
$ sudo yum -y update --security

This command will only download and apply the security patches
to your RPM-based server. You can use the following command to see
what security patches are available at a given time.

$ sudo yum info-sec

14. Upgrading RPM
Packages


The yum upgrade command will install newer versions of your
installed packages and remove the obsolete packages. The yum update
command demonstrated earlier may do this or may not, based on the
packages.

$ sudo yum upgrade
$ sudo yum -y upgrade

Although removing the obsolete packages might save you some
storage, they can cause trouble in many ways and sometimes even
break the system. That’s why our editors recommend you to use the
yum update command instead.

15. Installing Packages from Local
File


Sometimes you may already have the rpm package you want to
install in your machine. You can easily install them by using the
following yum command in Linux.

$ sudo yum localinstall abc-1-1.i686.rpm

The above command will install the given package from the
specified rpm file. If the file is in some other directory, simply
pass its location as shown by the following command.

$ sudo yum localinstall /path/to/abc-1-1.i686.rpm

16. Querying Packages for
Files


The yum package manager exposes a handy sub-command called
provides that allows the users to see which package contains a
certain file. This is very useful in a number of scenarios, as you
will see below.

$ sudo yum provides /bin/curl

This yum command will display the package that contains the curl command in Linux[9]. The below command will
list the package that has the file
/etc/httpd/conf/httpd.conf.

$ sudo yum provides /etc/httpd/conf/httpd.conf

yum provides command

17. Displaying all Package
Groups


Linux usually groups a set of packages based on their usages
like say System Tools or Graphics. Each group contains multiple
packages that serve a similar function. Admins often install a
group of packages altogether to save their time and refrain from
manually picking packages.

$ sudo yum grouplist

This command allows users to list all available and installed
package groups. You can now easily see which group of packages are
installed on your machine and which groups are available for
installation.

18. Installing Group
Packages


Once you have viewed which groups are available for
installation, you can proceed to install them. Use the following
command for doing this from your Linux terminal emulator[10].

$ sudo yum groupinstall 'Network Servers'
$ sudo yum -y groupinstall 'Network Servers'

This command will install all packages that are grouped under
‘Network Servers’. It will take care of any dependencies for you
and update old packages accordingly. You can use any group of
packages the same way to save your time later on.

19. Updating Group
Packages


What makes package groups really useful is that you can perform
operations on them like any other yum command. Say, you have
installed the group ‘Network Servers’ using the above command
earlier. Now, if you want to update the packages under this group,
you can easily do so by using the following command.

$ sudo yum groupupdate 'Network Servers'
$ sudo yum -y groupupdate 'Network Servers'

This command will see if any latest update is available for any
packages under ‘Network Servers’ and install them if it can find
any. It will take care of the dependencies for the user as
well.

20. Removing Group
Packages


Removing a package group using yum is as easy as installing
them. You can remove the group ‘Network Servers’ by using the
following yum command in Linux.

$ sudo yum groupremove 'Network Servers'
$ sudo yum -y groupremove 'Network Servers'

As you can see, yum allows users to install, update or remove
package groups just like it does with standalone packages. It makes
system management much easier for both general users and remove
server admins.

21. Displaying Enabled or Disabled
Repositories


Linux packages can reside in various yum repositories. You can
display the enabled repositories for your RPM-based system to see
from where a certain package can be installed.

$ sudo yum repolist
$ sudo yum repolist enabled

You can also list the disabled repositories by using the next
command. You can not install Linux packages from any of these
repos.

$ sudo yum repolist disabled

22. Displaying all
Repositories


The following yum command will list all yum repositories for
your RPM-based Linux distribution. This listing will contain
information like the repo name, the repo id, and indicate whether a
certain repo is enabled or disabled in your system.

$ sudo yum repolist all

This command is very handy for remote admins since it allows
them to check the available repositories at one go.

display all repos

23. Enabling or Disabling YUM
Repositories


As you’ve already seen, yum offers a broad set of repos for
packages. You can use the yum-config-manager to
enable or disable a yum repo very easily. It is a tool that allows
admins to manage the configuration options in yum and
repositories.

$ sudo yum repolist all
$ sudo yum-config-manager --enable extras

First, we’ve listed all yum repos for convenience. Next, we have
enabled the repository extras using
yum-config-manager and its repo id.

$ sudo yum-config-manager --disable extras

Finally, this command disables this extras repository. Remember
to use the repo id instead of the repo name when enabling or
disabling yum repos.

24. Updating Packages to Specific
Version


Earlier we have seen how to update a yum package or package
groups. However, in both of these cases, yum will update the
packages to the latest available version. What if you want to
update your package to a specific version. You can easily do this
using the below command.

$ sudo yum update-to abc-1-1.i686.rpm

When you run this command, yum will update the said
abc package to the specified version. Make sure
this version is available in your enabled repos else this command
will fail to execute.

25. Downgrading an Existing
Package


Sometimes you may want to downgrade certain packages due to
issues like untracked bugs or incompatibility of the latest release
with existing Linux shell scripts[11]. This is also fairly
easy when using the yum package manager.

$ sudo yum downgrade abc

This will downgrade the package abc to its
older release. You can use the following command to downgrade this
package to a specific version.

$ sudo yum downgrade abc-1-0.1.i686.rpm

However, if this version of the package is missing in your
active repo, this operation will fail to execute.

26. Installing and Removing
Packages at the Same Time


Sometimes you may want to install a new package and remove
another from your system. Thankfully, yum makes this very easy for
RPM-based Linux distributions. This is called a swap
installation.

$ sudo yum swap ftp lftp

When you run this command, yum will first remove the
ftp package from the system and then install the
lftp package. This is useful for many Linux admins
since it allows for much flexible package management.

27. Removing Cached
Packages


Yum makes a cache of each package you install on your system.
This can lead to storage issues over time, so you may want to
remove them every once in a while. Simply issue the following yum
command to remove all cached packages from your system.

$ sudo yum clean packages

This command deletes all downloaded packages from the yum cache.
Admins should use this command to stop the accumulation of excess
cached packages.

28. Cleaning Packages and
Metadata


Package managers like yum not only caches installation files but
also a lot of metadata. As you can guess already, too much of this
can cause trouble over time. However, you can easily clean up your
system by removing these using the following simple command.

$ sudo yum clean all

This command will eliminate cached installation files, header
files as well as clean cached data from the
dbcache, local rpmdb, plugins,
and other metadata information. However, yum may take some extra
time when you install new packages the next time.

29. Downloading Metadata for
Repositories


You can download and configure the yum metadata required for all
repositories that are currently enabled. This will speed up your
package management operations for the next use. See the below
command to learn how to do this.

$ sudo yum makecache

This command will make sure that the yum cache is up to date
with the latest metadata. You can also set the expiration time of
this metadata by configuring the metadata-expire setting found in
the /etc/yum.conf file.

30. Displaying Package
Dependencies


Linux packages are modular by design and will often depend on
many other packages to provide their functionality. You can list
all the dependencies of a yum package by using the following yum
command in Linux.

$ sudo yum deplist nfs-utils

This command will list all the dependencies for the rpm package
nfs-utils. It will also highlight the packages
that provide those packages and the name of the yum repositories
that contain them. This is a very useful command for server admins
since it makes easy to visualize the dependencies.

yum command to display package dependencies

31. Completing Remaining
Transactions


Sometimes situations may arise when your Linux workstation or
server fails to complete ongoing package management jobs due to
system failure or some unwanted reasons. The yum package manager
allows admins to complete these operations pretty easily, as
demonstrated by the below command.

$ sudo yum-complete-transaction

The above command will locate all unfinished transactions and
complete them accordingly. It makes package management hassle-free
in times of system maintenance. You can also clean only the
transaction journal files and exit by using the below command.

$ sudo yum-complete-transaction --cleanup-only

32. Skip Broken Packages when
Updating


Since repos contain a substantial number of packages, users
often have to deal with incomptible or broken packages. These occur
mostly during system updates and can render the management task
difficult. Luckily, you can use the following command for telling
yum to skip these packages.

$ sudo yum update --skip-broken

So don’t worry if your system fails during a package management
job and leaves broken packages. You’ll be able to clean them easily
using the above two commands.

33. Displaying Update
Information


As a system administrator, it is essential to monitor your
package updates thoroughly. Thankfully, the updateinfo sub-command
allows us to visualize the update process very easily.

$ sudo yum updateinfo summary

This command will display all newly available bug fixes and
security patches for your system. Use the following command to get
information about the security updates only.

$ sudo yum updateinfo security

Use the below command to get information about all new
updates.

$ sudo yum updateinfo list new

34. Reinstalling
Packages


Users may often encounter with broken packages due to a faulty
installation or configuration problem. One of the quickest ways to
resolve this issue is reinstalling the process or processes
altogether. You can do this easily by following the below yum
command.

$ sudo yum reinstall PACKAGE-NAME
$ sudo yum reinstall curl

The last command will reinstall the current version of the curl command in Linux[12] on your RHEL/CentOS
system. You will find this command quite useful when
troubleshooting systems.

35. Listing Installed and
Available Kernels


The Linux kernel is the core component of all Linux distributions[13]. There are several
versions of these available at a given time. You can display the
currently installed kernel of your system as well as all available
ones by using the below simple command.

$ sudo yum list kernel

It will display the kernel information for your system alongside
their version and availability. This is useful if you want to
upgrade or downgrade to a different kernel version using yum.

36. Download Packages but Don’t
Install


Sometimes you may want to download the rpm package of an
application without installing the package itself. You can install
this package later by using the localinstall sub-command of
yum.

$ sudo yum install --downloadonly --downloaddir=/home/user/downloads curl

The above command will download the curl package and place it
into the /home/user/downloads directory. Simply
change this path to store the packages in a different part of
the Linux file system[14].

37. Adding New
Repositories


RHEL or CentOS admins can easily add new repositories. One
common way is to edit the configuration file in
/etc/yum.repos.d. However, recent versions of yum
allow admins to add new repos by using the yum-config-manager tool.
Simply use the below command for adding new repos.

$ sudo yum-config-manager --add-repo="https://mirror.xarnet.edu.au/pub/centos/7"

Replace the string value of the –add-repo
option with the URL of the repository you want to add.

38. Excluding Packages during
Installations/Updates


Sometimes you may want to exclude certain packages from your
update or installation operations. This is fairly straightforward
using yum. Simply use th following format to do this from the
terminal.

$ sudo yum check-update

$ sudo yum update -x sqlite-libs.x86_64

First, we have checked which updates are available currently.
Then we’ve performed a system-wide update but omitted the package
sqlite-libs.x86_64. So, simply use the
-x option to omit rpm packages from your
operation.

39. Finding Repositories of a
Package


Admins can easily find out from which repo a specific package or
a set of packages comes from. You will need to use the tool
find-repos-of-install in order to perform this
operation. This is available only after installing the
yum-utils package.

$ sudo yum install yum-utils

$ sudo find-repos-of-install curl

First, we’ve installed the yum-utils package that contains the
required command. Then we have used the
find-repos-of-install command to find out which
repository has the curl package.

find repo information

40. Synchronizing All
Packages


Admins can synchronize their rpm packages to make sure all
installed packages are on par with their repository versions. Yum
will upgrade or downgrade your packages based on the latest
available versions found in the enabled repositories.

$ sudo yum distribution-synchronization

When you run this command, yum will download newer updates,
remove obsolete packages, and even downgrade packages if required.
This yum command is very useful for system maintenance since it
provides an easier route to synchronization.

41. Displaying Multiple Version of
a Package


You can use the –showduplicates option of yum
to display all the available versions of a package. This has
several use cases when troubleshooting legacy systems.

$ sudo yum --showduplicates list httpd

This command will show all versions of the
httpd package available to your system. It is also
useful when you are looking to find the specific name of an RPM
package before proceeding to installation.

$ sudo yum search --showduplicates emacs

42. Displaying Repository
Information


You’ll learn how to display information about yum repositories
by using the following simple command. This command provides
various information about your repositories, including repo id,
name, last update date, size, and baseurl.

$ sudo yum repoinfo

Use the following yum commands to limit this result to either
enabled or disabled repositories.

$ sudo yum repoinfo enabled
$ sudo yum repoinfo disabled

You can also use the repoinfo sub-command for
finding the repository information of a specific package or set of
packages, as demonstrated below.

$ sudo yum repoinfo nginx

43. Working within a Specific
Repository


The repo-pkgs command of yum allows admins to
install or update packages from specified repositories. The below
command shows you how to list all packages contained within a
specific repo.

$ sudo yum repo-pkgs AppStream list

This command will list all packages offered by the AppStream
repo. Use the following command to install a package from this
repository.

$ sudo yum repo-pkgs AppStream install wget

You can also install or remove all packages of a repo using the
following simple commands.

$ sudo yum repo-pkgs AppStream install
$ sudo yum repo-pkgs AppStream remove

44. Using the Interactive YUM
Shell


Yum provides an easy to use and robust interactive
shell
[15] that allows admins to
perform package management tasks more clinically. Simply type the
following command at your command prompt to invoke this interactive
shell.

$ sudo yum shell

You’ll be presented with a prompt that starts with ‘>’. Start
typing in your yum commands in this shell one after another.

> list updates
> update

Simply enter ‘quit‘ or press Ctrl +
C
to terminate this shell. You can also use a text file that
contains all your commands in different lines. Yum will run these
commands one after another.

$ sudo yum filename

45. Displaying Transaction
History


Use the following command to view all the commands performed by
yum till now. You can undo or redo older transactions using this
very easily.

$ sudo yum history

This list displays the latest operations at the start. You can
analyze a specific transaction by using their ID, as illustrated
below.

$ sudo yum history info 10

Use the following commands to undo/redo certain transactions.
The trailing -y option skips the confirmation
prompt.

$ sudo yum history undo 20 -y
$ sudo yum history undo 30 -y

46. Hiding Yum
Output


By default, yum provides a select set of information about its
operations. You can hide these data by using the following simple
command.

$ sudo yum install httpd -y -q
$ sudo yum install httpd --assumeyes --quiet

These commands are equivalent and will install the
httpd package without asking for user confirmation
or providing any textual output in your Linux terminal.

47. Increasing
Verbosity


You can also do the opposite of the above commands by using the
-v or –verbose switch of yum. In
this case, yum will provide a substantial amount of output about
the operation taking place.

$ sudo yum install httpd -v
$ sudo yum install httpd --verbose

We’ve omitted the -y switch since chances are
you want to inspect through the operation before proceeding. This
is an excellent tool for debugging package management
operations.

48. Displaying the Help
Page


You can find out the summarized information of all possible
command combinations by using any of the following commands.

$ yum -h
$ yum --help

Additionally, use the following command to find help about a
specific yum operation.

$ yum help autoremove

display yum help

49. Consulting the
Manual


The manual page contains detailed information of all
command-line options and their usage. If you’re an absolute
beginner, this should be the place to start on.

$ man yum

Consult this documentation whenever you’re having trouble with
certain commands.

50. Displaying Version
Information


Use the following simple command to find out which version of
yum and dnf is installed on your
machine. It also shows the build information for that version.

$ yum --version

Ending Thoughts


Yum commands are extremely versatile and provide all the
functionalities required to maintain modern RHEL or CentOS
packages. No matter whether you’re a professional sysadmin or a
starting Linux user, mastering these commands will help you handle
RPM-based distributions at ease. Our editors have tried to include
all the commands that users may need to know for maintaining their
system. Hopefully, we were able to provide you the ultimate guide
you’re looking for. Let us know your thoughts in the comment
section and feel free to ask any questions.

References

  1. ^
    YUM
    (Yellowdog Updater, Modified)

    (en.wikipedia.org)
  2. ^
    RPM-based Linux distributions
    (ubuntupit.com)
  3. ^
    Linux or
    BSD system
    (ubuntupit.com)
  4. ^
    Linux
    terminal
    (ubuntupit.com)
  5. ^
    Linux
    shell scripts
    (ubuntupit.com)
  6. ^
    the
    Linux grep command
    (ubuntupit.com)
  7. ^
    awk
    command in Linux
    (ubuntupit.com)
  8. ^
    RHEL or
    CentOS servers
    (ubuntupit.com)
  9. ^
    the curl
    command in Linux
    (ubuntupit.com)
  10. ^
    Linux
    terminal emulator
    (ubuntupit.com)
  11. ^
    Linux
    shell scripts
    (ubuntupit.com)
  12. ^
    the
    curl command in Linux
    (ubuntupit.com)
  13. ^
    Linux
    distributions
    (ubuntupit.com)
  14. ^
    the
    Linux file system
    (ubuntupit.com)
  15. ^
    easy
    to use and robust interactive shell

    (ubuntupit.com)

Read more