The “yum” Command in Linux [With 9 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The yum (Yellowdog Updater Modified) command in Linux is a command line package manager. This rpm-based package manager is widely used in RedHat-based distros like CentOS or RHEL to install, update, or remove packages, and so on. To do so, you can use the default yum command along with its different useful options.

In this article, I’ll demonstrate the most common uses of the yum command in Linux with relevant examples.

Syntax of “yum” Command

The syntax of the yum command is as follows:

yum [options] [command] [package ...]

Note: Everything inside square brackets is optional in this syntax. Three dots after the package indicate that multiple packages can be passed to the argument.

Options of “yum” Command/ Cheat Sheet

The yum command comes up with a lot of options. To check out all the options, you can check out the man page of the yum command:

man yum

Some of the most frequently used yum commands are:

Command Description
yum install package Installs a package
yum reinstall package Reinstalls a package
yum update package Updates a package
yum list Lists the packages
yum remove package Removes package
yum downgrade package Downgrades package

9 Examples of Using “yum” Command in Linux

You can use the yum command to manage the packages. This includes installing, updating, or removing the packages, and so on. Let’s explore the most common package management tasks using the yum command:

1. Installing a Package

To install a single package named php using the yum command, you can type the following command line in the terminal and hit ENTER:

sudo yum install php
EXPLANATION

The sudo command at the beginning of the sudo yum install command line gives root privilege to the user.

installing a single package using "yum" commandFrom the image above, you can see the php package is installed using the yum command.

Note:

  1. To install group packages, use the yum groupinstall command, followed by the group name. The syntax is:

    yum groupinstall GroupName
  2. To install a repository, use the yum install command followed by the repository name:

    yum install RepositoryName
  3. To install a package from a particular repository, use the following syntax:

    yum enablerepo=RepositoryName install PackageName
  4. To install a package automatically without asking for confirmation, you can use the yum command with the option -y:

    yum -y install PackageName
  5. To view more information while the installation takes place, use the yum command with the option -v (useful for debugging or monitoring progress):

    yum -v install PackageName
  6. To install a rpm package from a local file in RHEL 5 or older versions, you can use the yum localinstall command followed by the path name:

    yum localinstall PathName

From RHEL 6 or later versions, you can simply use the yum install command instead of the yum localinstall command.

2. Reinstalling Package

To reinstall an already existing package, you can use the yum reinstall command. For example, type the following command in the terminal and hit ENTER to reinstall the php command:

sudo yum reinstall php

reinstalling a package using "yum" commandThe above image shows the reinstallation process of the php package.

3. Updating Package

To update a package, you can use the yum update command. For instance, to update the firefox package, type the following command in the terminal and press ENTER:

sudo yum update firefox

updating a package using "yum" commandThe above image shows the updating process of the firefox package.

Note:

  1. To update a package group, use the following syntax:

    yum groupupdate PackageName
  2. To update the entire system, you can use the following command:

    yum update
  3. To update the security of your system, use the security update command:

    yum update --security
  4. To check which packages have updates available, you can use the following command:

    yum check-update
  5. To update to a specific version of a package, you need to mention the version of that package:

    yum update-to PackageVersion
  6. To exclude a specific package while updating the entire system, you can mention the specific package that you don’t want to update:
    yum update exclude=PackageName

4. Listing of Packages

The yum list command, without any argument, returns a list of all the available packages. You can pipe its output into the head command to view a selective number of packages. For example, to view the first 10 packages, you can use the following command:

sudo yum list | head -10

listing packages using "yum" commandIn the above image, you can see a list of the packages.

Note:

  1. To list all the groups, you can use the following command:

    yum grouplist
  2. To list only the installed packages, use the command like this:

    yum list installed
  3. To list all the available repositories, use the following command:

    yum repolist all
  4. To list only the enabled repositories, you can use the command like this:

    yum repolist
  5. To list packages installed using the currently disabled repositories, type the following command in the terminal and hit ENTER:

    yum list extras
  6. To list the dependencies of a package, you can use the following command:
    yum deplist PackageName

5. Removing Package

To remove a package, you can use the yum remove command, followed by the package name you want to remove. For example, type the following command in the terminal and press ENTER to remove the previously added php package:

sudo yum remove php

removing a package using the "yum" commandThe above image shows the removal process of the php package.

Note:

  1. To remove a group, use the yum groupremove command:

    yum groupremove GroupName
  2. To remove unused dependencies, you can use the following command:

    yum autoremove

6. Downgrading Package

To downgrade (revert a software program or package to an older version) a package, you can use the yum downgrade command. For instance, type the following command in the terminal and hit ENTER to downgrade the php package:

sudo yum downgrade php

downgrading a package using "yum" commandIn the above image, you can see the downgrading process of the php package.

Note: Downgrading can introduce conflicts with other packages that might rely on the newer version. This can lead to system instability or unexpected behavior. So, always back up your system before attempting a downgrade in case something goes wrong and you need to restore your system.

7. Searching Package Using “yum” Command

To search for a package, you can use the yum search command, followed by the package name you want to search for. For example, to search the php package, use the following command:

sudo yum search php

using "yum" command for searching a packageThis image shows the search result of the php package.

Note:

  1. To get info about a repository:
    yum repoinfo RepositoryName
  1. To get the information about a package, use the yum info command:
    sudo yum info PackageName

8. Searching a File in Packages

To search a file in a package, use the yum provides command followed by the path to the file name. For example, to search a specific file among the packages, write the following command in the terminal and hit ENTER:

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

This command is used to search for the package that provides the specified file (/etc/httpd/conf/httpd.conf in this case). If I run the command, yum will search through all available packages in my system and their contents to find any packages that match our specified file name. Then it will display the detailed information about the package that contains the file. This information includes the package name, version, repository, and so on.

searching a specific file using "yum" commandThe image above shows the searching process for a specific file.

9. Repository Management

To enable a repository, use the yum-config-manager command. For that, first, let’s check the status of all the repositories by using the following command:

sudo yum repolist all

This returns the status of all the repositories.

disabled repositoryIn the above image, you can see the rhel-atomic-7-cdk-3.6-source-rpms is disabled. To enable this repository, you can use the following command:

sudo yum-config-manager --enable rhel-atomic-7-cdk-3.6-source-rpms

Now if you check the status of the repository, you’ll see the repository is enabled.

Type the following command in the terminal and hit ENTER:

sudo yum repolist all

using "yum" command to enable a repositoryNow you can see the repository is enabled.

Note:  To disable a repository, you can use the following syntax:

sudo yum-config-manager --disable RepositoryName

Miscellaneous Use Cases of “yum” Command

The yum is a multi-purpose command. You can perform a wide range of tasks using the yum command:

Case 1: Cleaning “yum” Cache

To clean the cache files, you can use the following command:

sudo yum clean all

cleaning all cache files using "yum" commandThe image shows the cleaning of 17 cache files.

Case 2: Show “yum” History

To view all the history of using the yum command in the system, use the yum history command:

sudo yum history

using "yum" command to view transaction historyIn the image above, you can observe the command history, displaying transaction IDs, command lines, dates, and times. A “transaction” refers to any operation executed using the yum command. For instance, the command "sudo yum install php" represents a transaction identified by ID 7, while ID 8 corresponds to the transaction “sudo yum downgrade php”.

Case 3: Show a Specific Transaction

To view a specific transaction, you can use the yum history info command, followed by the transaction ID. For example, to show the details of the transaction ID 7, use the following command:

sudo yum history info 7

showing a specific transaction using "yum" commandThe image contains the details about the transaction ID 7.

Case 4: Undo a Transaction

To undo a transaction, you can use the yum history undo command, followed by the transaction ID. For example, in our case, the transaction ID 8 was downgrading the php package. Now to undo this transaction that is, upgrade the php package, you can use the following command:

sudo yum history undo 8

using "yum" command to undo a transactionFrom the image, you can see, the upgrade is taking place.

Note: To undo a transaction, you can also use rollback:

sudo yum history undo Transaction_ID

Rollback is similar to undo. The difference is that it rolls back everything from that transaction to the most recent version of the system.

Case 5: Redo a Transaction

To redo a transaction, you can use the yum history redo command. For instance, to redo the transaction ID 8, that is downgrading the php package in this case, you can use the following command:

sudo yum history redo 8

using "yum" command to redo a transactionFrom the image above, you can see redoing the transaction ID 8, which is downgrading the php package is taking place.

Case 6: Interactive “yum” shell

The yum command has its own interactive shell. To use the interactive yum shell, first of all, you need to use the following command:

sudo yum shell

Type your password as the prompt asks for. Now as the shell appears, you can use it just like a regular shell to install, update, or remove packages and so on. In this shell, sometimes you need to use the run command to execute a command. For example, to remove the php package, type the command line and hit ENTER:

remove php

Finally, type run and hit ENTER:

using "yum" shell to remove a transactionIn the image above, you can see the removal of the package php is taking place.

The special feature of the interactive yum shell is that you can execute multiple command lines during a single yum execution. For example, you can write the following command lines:

sudo yum shell

> install php
> update firefox
> remove vsftpd

> run

As soon as you type the run command and hit ENTER, this will install the package php, update firefox, and remove vsftpd simultaneously.

Conclusion

The yum command is a command line package manager that manages the installation, update, removal of packages, and so on. In this article, I’ve demonstrated the yum command in Linux with some suitable examples. Hopefully, these examples will help you understand the yum command thoroughly. Try out the examples yourself and sharpen your Linux package management skills. Feel free to leave a comment if you have any queries.

People Also Ask

What is yum and RPM?

yum is a command line package manager that you can use to install, update, or delete packages. And RPM is the packaging format. The yum command is more compatible than RPM in case of dependency management and updating packages.

How to troubleshoot repository issues?

To troubleshoot repository issues recheck the network connection as these issues may occur due to network issues. Also cleaning the cache using the yum clean all command comes in handy while solving the repository issues.

How do you deal with dependency conflicts?

To deal with dependency conflicts, you can simply use the yum command with the --skip-broken option.

What is the full form of yum?

The full form of yum is “Yellowdog Updater Modified”. This is a command-line package manager.

What is the yum list in Linux?

The yum list is a command that you can use to get various information about the packages. You can also modify the command behaviour to get information about all the available packages or only the installed ones by using different options along with the yum list command.

Rate this post
Avatar photo

Hadi Ul Bashar holds a BSc degree in Biomedical Engineering from Bangladesh University of Engineering and Technology. In January 2023, Bashar joined Softeko as an Excel and VBA content developer. Since then, he has authored over 50 articles and created over 70 videos. Also, he has an interest in Linux. Currently, he is working as a Linux content developer executive. Here, he aims to create useful Linux content for its users. Reading books and travelling are his favourite pastimes. Read Full Bio

Leave a Comment