- A Cloud Guru
Managing Packages on RedHat/CentOS Systems
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.
Table of Contents
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
yumcommand to search for any packages with apache or http in their names:
yum search 'apache http'
The Apache server comes with an
httpdfile. Knowing this, we can use
yumto 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
systemctlcommand 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
rpmto query for its configuration details, documentation, and other information. Using
rpm -qacan 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
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
elinkspackage isn't installed:
rpm -q elinks
Now we should make sure the development team did in fact download the correct
rpmcommand, we can query that
elinkspackage 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 localinstall /tmp/elinks-0.12-0.37.pre6.el7.0.1.x86_64.rpm
Answer y at the prompt.
Finally, let's use the
elinkscommand to make sure that the package installed correctly, and browse the
If we land at the CentOS Apache welcome page, we're all set.
What's a lab?
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.