Managing Packages on RedHat/CentOS Systems

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Updating, installing, removing and querying packages are core skills for anyone managing Linux distributions. Some of the most popular package management tools include the `yum` and `rpm` tools included in the Red Hat/CentOS Linux distributions.

During this activity, you will work with the Red Hat/CentOS high-level package command `yum` for updating, installing and removing packages, since it automatically manages packages required for dependencies. You will also use the Red Hat/CentOS low-level package command `rpm` to query information about installed packages. After completing this activity, you should know how to properly manage software packages on Red Hat/CentOS systems.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Assume That the YUM Metadata and Cache Are Out-Of-Date and Resolve the Issue so That We Can Update the System

First, we’ll clean the existing YUM metadata and cache, and create a fresh one:

yum clean all
yum makecache

Next, let’s list the available updates:

yum list updates

Finally, we need to update the software packages on the system:

yum -y update

This may take a little while, since we’re downloading updates for everything currently installed on the system.

Use yum to Search for the Apache HTTP Package, Find What Provides /sbin/httpd, Install the Correct Package for the `httpd` Service, and Then Use the systemctl Command to Make Sure the `httpd.service` Starts

Use the yum command to search for any packages with apache or http in their names:

yum search 'apache http'

The Apache server comes with an httpd file. Knowing this, we can use yum to find which package includes (provides) such a file:

yum provides httpd

Now that we know the name of the actual package we need to install, we can do it:

yum -y install httpd

Use the systemctl command to start the httpd.service, and enable it to start when the system boots. This will do both:

systemctl enable httpd --now

Now check the status of the httpd.service, and would should see active and running in the output:

systemctl status httpd.service
Use rpm to Query for Configuration, Documentation, and Information about Which Package Owns /sbin/httpd, as Well as All Installed Packages

After installing a package like httpd, we can use rpm to query for its configuration details, documentation, and other information. Using rpm -qa can provide information about all the packages installed on the system.

Let’s look at any documentation files belonging to the package:

rpm -qd httpd

Show configuration files:

rpm -qc httpd

Show which package owns a file (in this case /sbin/httpd):

rpm -qf /sbin/httpd

Show all packages installed on the system:

rpm -qa | wc

We piped this command into wc, just so our screen wouldn’t be inundated with information, but we can see that there are several hundred packages installed on the system. To look at them in order of install time, from oldest to newest:

rpm -qa --last | tac

At least this way, what’s down near our new command prompt is the most recently installed packages.

Now if we just want to see packages that start with httpd, we’d run:

rpm -qa 'httpd*'
Query and Install the Elinks Package in the /tmp Directory, and Verify That Elinks Works by Browsing the Local Website

Let’s first make sure that the elinks package isn’t installed:

rpm -q elinks

Now we should make sure the development team did in fact download the correct elinks package:

ls /tmp/elinks*.rpm

Using the rpm command, we can query that elinks package and get some information about it:

rpm -qp /tmp/elinks-0.12-0.37.pre6.el7.0.1.x86_64.rpm

Now let’s see what scripts will execute when the package is installed:

rpm -qp --scripts /tmp/elinks-0.12-0.37.pre6.el7.0.1.x86_64.rpm

This is good information to have. If the package files are potentially not from a trusted source, we’re going to want to know what scripts will run during the install process, and what they do.

We can try to install the package with this:

rpm -ivh /tmp/elinks-0.12-0.37.pre6.el7.0.1.x86_64.rpm

Alas, we will probably have unmet dependencies. And when we try to install the packages in these error messages, we may find that those have unmet dependencies. It can be a mess. Let’s try this with yum instead:

yum localinstall /tmp/elinks-0.12-0.37.pre6.el7.0.1.x86_64.rpm

Answer y at the prompt.

Finally, let’s use the elinks command to make sure that the package installed correctly, and browse the http://localhost website:“`

elinks http://localhost



If we land at the CentOS Apache welcome page, we're all set.

Additional Resources

Our development team is working on their new web-based API. They want us to install the Apache HTTP Server and test it for local access. They want to be able to test the API with a command line interface. They found a terminal browser they like, but the version they need to run is a bit different from the version in the official repository.

They have downloaded the appropriate package for their system and architecture, but claim they are unable to install it because of several missing dependencies. They have asked us to resolve the issue, and have provided us with credentials and connection information for their client testing system.

We will need to successfully install the elinks using the .rpm file that the development team downloaded. We can resolve the unmet dependencies however we want, but using the yum command is recommended. The version of elinks that has already been downloaded is the version that we need to install, and it is sitting in /tmp. We'll use the appropriate rpm command to verify the version that is installed. Once we verify the application is installed and running properly with access to the local web server, we can turn the system back over for their use.

Use the credentials provided on the hands-on lab overview page, and log in as cloud_user. Since we'll need root privileges for what we've got to do, let's also run sudo -i to start an interactive root shell right away.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?