102.5. Use RPM and YUM package management
102.5 Use RPM and YUM package management
Weight: 3
Description: Candidates should be able to perform package management using RPM and YUM tools.
Key Knowledge Areas:
Install, re-install, upgrade and remove packages using RPM and YUM
Obtain information on RPM packages such as version, status, dependencies, integrity and signatures
Determine what files a package provides, as well as find which package a specific file comes from
Terms and Utilities:
rpm
rpm2cpio
/etc/yum.conf
/etc/yum.repos.d/
yum
yumdownloader
In this lesson we learn how to work with packages in RedHat Distributions. If you are not familiar with Package and package Manager concepts in linux please study first part of previous lesson.

rpm
RPM (Red Hat Package Manager) is a powerful Package Manager, which can be used to build, install, query, verify, update, and erase individual software packages.
A package consists of an archive of files and meta-data used to install and erase the archive files. The meta-data includes helper scripts, file attributes, and descriptive information about the package.
Packages come in two varieties: binary packages, used to encapsulate software to be installed, and source packages, containing the source code and recipe necessary to produce binary packages. RPM is the only way to install packages under Linux systems, if you’ve installed packages using source code, then rpm won’t manage it.

RPM deals with .rpm files, which contains the actual information about the packages such as: what it is, from where it comes, dependencies info, version info etc.
Where to find RPM packages
list of rpm sites, where we can find and download all RPM packages:
RPM keeps the information of all the installed packages under /var/lib/rpm database.
They are all binary files, try cat Basenames to see.
There are five basic modes for RPM command:
Install : It is used to install any RPM package.
Remove : It is used to erase, remove or un-install any RPM package.
Upgrade : It is used to update the existing RPM package.
Verify : It is used to verify an RPM packages.
Query : It is used query any RPM package.
Install an RPM Package
-i is used for installing an rpm software package
-v verbose for a nicer display
,-h print hash marks as the package archive is unpacked.
Check an Installed RPM Package
-q option query a package:
List all files of an installed RPM package
Use -ql (query list) with rpm command:
Query a file that belongs which RPM Package
-qf (query file) option help us to find out which package belongs to a file.
Query a Information of Installed RPM Package
-qi (query info) option will print the available information of the installed package.
Get the Information of RPM Package Before Installing
-qip (query info package) will print the information of a package , as the package has not been installed there is nothing to read by rpm in its data base, so we need to give full name of the package and it would provide required information directly from rpm package:
-p is used to query information from rpm package. We can omit -p and use Package name instead rpm -qi htop .
check dependencies of RPM Package before Installing
Use -qpR options to do a dependency check before installing or upgrading a package
-R List capabilities on which this package depends. we can easily use rpm -qR PackageName to query an installed package.
Query configuration file of Installed RPM Packae
-qc (query configuration file) will query an installed package for its configuration files, if it has any:
If the package is not installed use -qpc instead to query a rpm package.
Query documentation of Installed RPM Package
-qdf(query document file) gives a list of available documentation of an installed package:
Verify a installed Package
-V(verify) verifies a package:
No news is good news.When verifying a package, RPM produces output only if there is a verification failure. When a file fails verification, the format of the output is a bit cryptic, but it packs all the information you need into one line per file. Here is the format: SM5DLUGT c <file> . As an example:
Where:
S is the file size.
M is the file's mode.
5 is the MD5 checksum of the file.
D is the file's major and minor numbers.
L is the file's symbolic link contents.
U is owner of the file.
G is the file's group.
T is the modification time of the file.
c appears only if the file is a configuration file. This is handy for quickly identifying config files, as they are very likely to change, and therefore, very unlikely to verify successfully.
<file> is the file that failed verification. The complete path is listed to make it easy to find.
Verify all RPM Packages
Use -Va(Verify all) to verify all the installed rpm packages.
use rpm -Vac to just verify configuration files.There would be some common system script which are routinely changed.
Verify a RPM Package
Verifying a package compares information of installed files of the package against the rpm database.
The-Vp (verify package) is used to verify a package.
List all Installed RPM Packages
-qa (query all) option, will list all the installed rpm packages.
use --last option to list recently installed RPM Packages.
Upgrade a RPM Package
-U upgrades or installs the package currently installed to a newer version. This is the same as install, except all other version(s) of the package are removed after the new package is installed.
One of the major advantages of using this option is that it will not only upgrade the latest version of any package, but it will also maintain the backup of the older package so that in case if the newer upgraded package does not run the previously installed package can be used again.(via rpm --oldpackage switch or using yum downgrade )
rpm -ivh vs rpm -Uvh
rpm -ivh just installs a package and if the package is already installed it won't do any things, but rpm -Uvh installs it, even if it exists.
Also rpm -ivh might cause having multiple version of a package at the same time but by using rpm -Uvh we are sure that we just have the latest version.
-F will upgrade packages, but only ones for which an earlier version is installed.( means upgrade if installed other wise do noting)
Remove a RPM Package
-e (erase) option is used to remove package (add v or vv for more verbosity):
rpm take care of dependencies while removing a package and does not remove package dependencies. on the other hand if a package is required by other pacakage(d) rpm avoid removing that.The –nodeps (Do not check dependencies) option forcefully remove the rpm package from the system. But keep in mind removing particular package may break other working applications.
note:If you've made changes to a configuration file that was originally installed by RPM, your changes won't be lost if you erase the package.
What you can do is just run "rpm -qc packageName" which will show you which configuration files were installed on your system by an rpm. When you have uninstalled the rpm, you can search on your system if any of the files or their backups remain on your system and remove them manually.
rpm2cpio
From time to time, we might find it necessary to extract one or more files from a package file. One way to do this would be to:
Install the package
Make a copy of the file(s) you need
Erase the package
An easier way would be to use rpm2cpio.
What Files Are In a RPM Package?

A rpm package is consist of some of files and directories which has been archived in cpio format, in addition some descriptions and dependencies have been added to that.
What does rpm2cpio do?
As the name implies, rpm2cpio takes an RPM package file and converts it to a cpio archive. next we need to open cpio archive in order to have orginal file structure.

In this case, the cpio options-i Extract one or more files from an archive, -vverboe, list the files processed, and -dCreate leading directories where needed.(We will talk about cpio in next courses)
rpm2cpio takes only only one argument, and even that's optional! The optional argument is the name of the package file to be converted. (If there is no filename specified on the command line, rpm2cpio will simply read from standard input and convert that to a cpio archive.)
While there's nothing wrong with using rpm2cpio to actually create a cpio archive file, it's takes a few more steps and uses a bit more disk space than is strictly necessary. A somewhat cleaner approach would be to pipe rpm2cpio's output directly into cpio:
we used the-t option to direct cpio to produce a "table of contents" of the archive created by rpm2cpio. This can make it much easier to get the right filename and path when you want to extract a file. An easier way to exctract would be rpm2cpio package.rpm | cpio id .
Warning! Becarefull when removing extracted package (usr vs /usr)
YUM
The YUM (Yellowdog Updater Modified) is an open-source command-line package-management utility for Linux operating systems using the RPM Package Manager. Yum allows automatic updates, package and dependency management, on RPM-based distributions.
As a high-level tool,like the Advanced Packaging Tool (APT) from Debian, yum works with software repositories (collections of packages), which can be accessed locally or over a network connection.
Yum is implemented as libraries in the Python programming language, with a small set of programs that provide a command-line interface. GUI-based wrappers such as yumex also exist.
/etc/yum.conf
The configuration file for yum and related utilities is located at /etc/yum.conf.
This file contains one mandatory [main] section, which allows us to set Yum options that have global effect, and can also contain one or more [repository] sections, which allow us to set repository-specific options. However, it is recommended to define individual repositories in new or existing .repo files in the /etc/yum.repos.d/ directory.
/etc/yum.repos.d
YUM Repository configuration files are stored in /etc/yum.repos.d directory. It contains several .repo files.
Lets take a look at CentOS-Base.repo file:
Repository configuration files tell yum information about the actual repository (where package files are physically located). While there are a number of optional elements, each .repo file is required to have:
Repository ID - A one word unique repository ID e.g. [localrepo].
Name - A human readable name for the repository e.g. name=Awesome Local Repo
MirrorList : A mirror list is a list of URLs where Package repositories are stored/present.
Baseurl - A URL to the repodata directory (where the actual files are kept). file://path, ftp://link, http://link, and https://link addresses are all valid options.
Enabled - Whether or not to enable the repository for use when performing updates and installs e.g. enabled=1 (1 means "use this repository", 0 defines "do not use this repository").
Gpgcheck - Enable/disable GPG signature checking (example: gpgcheck=1)
Gpgkey - URL to the GPG key (example: gpgkey=http://mirror.cisp.com/CentOS/6/os/i386/RPM-GPG-KEY-CentOS-6\
YUM can use numerous third party repositories to install packages automatically by resolving their dependencies issues.
List Enabled Yum Repositories
yum repolist list all enabled Yum repositories in your system:
To list all Enabled and Disabled Yum Repositories use yum repolist all command.
Install a Package with YUM
We can install new software on Red Hat/CentOS Linux with yum install packagename command from console.
Running this command first checks for existing YUM Repository configuration files in /etc/yum.repos.d/ directory. It reads each YUM Repository configuration file to get the information required to download and install new software, resolves software dependencies and installs the required RPM package files.
use -y option if you do not like to be asked for confimation. If you have a rpm package use yum localinstall abc.rpm .
Removing a Package with YUM
yum remove packagename remove a package completely with their all dependencies.
Same way the remove command will ask confirmation before removing a package. To disable it just add option -y .
Search for a Package using YUM
Use yum search function to search all the available packages to match the name of the package you specified.
Get Information of a Package using YUM
Withyum info packagename we can get information of a package before installing or an installed package:
Get information about dependencies of a package
Use yum deplist command to know about dependencies of a package which would be installed on our system:
yum installautomatically installs all of them.
Yum Provides Function
yum provide finds packages that provide the queried file:
also we can useyum whatprovide /*filename instead.
List all Available Packages
yum list list all the available packages in the Yum database.
List all Installed Packages using YUM
Working with yum Cache
By default, yum deletes downloaded data files when they are no longer needed after a successful operation. This minimizes the amount of storage space that yum uses. However, we can enable caching, so that the package files downloaded by yum stay in cache directories. By using cached data, you can carry out certain operations without a network connection, we can also copy packages stored in the caches and reuse them elsewhere.
Yum stores temporary files in the/var/cache/yum/$basearch/$releasever/directory,
Each configured repository has one subdirectory.T o change the default cache location, modify the cachedir option in the [main] section of the /etc/yum.confconfiguration file.
Enabling the cache
To retain the cache of packages after a successful installation, we can enable the cache editing keppcache = 1 in the [main] section of/etc/yum.conf.
To download and make usable all the metadata for the currently enabled yum repositories, use yum makecache command.It makes sure that the cache is fully up to date with all metadata.This make sure that the cache is fully up to date with all metadata. To set the time after which the metadata will expire, use the metadata-expire setting in/etc/yum.conf.
Using yum in Cache-only Mode
To carry out a yum command without a network connection, add the -C (not -c )or --cacheonly command-line option. With this option, yum proceeds without checking any network repositories, and uses only cached files. In this mode, yum may only install packages that have been downloaded and cached by a previous operation.
clearing the yum caches
It is often useful to remove entries accumulated in the /var/cache/yum/ directory. If we remove a package from the cache, we do not affect the copy of the software installed on our system. To remove all entries for currently enabled repositories from the cache, run yum clean all as a root.
Check for Available Updates using Yum
use yum check-update To find how many of installed packages on our system have updates available:
Update System using Yum
yum update keep our system up-to-date with all security and binary package updates
Updating a Package using YUM
yum update packagenamewill update a package and automatically resolves all dependencies issues and install them.
If you have a rpm package you can use yum localupdate abc.rpm .
YUM update vs YUM upgrade
yum upgradeandyum updatewill perform the same function that update to the latest current version of package.
yum upgradeforces the removal of obsolete packages, whileyum updatemay or may not also do this. The removal of obsolete packages can be risky, as it may remove packages that you use. This makesyum updatethe safer option.note: The behaviour might be different based on your distribution and version.
Working with Group Packages
In Linux, number of packages are bundled to particular group , called Group Packages. Instead of working with individual packages with yum, we can work particular group that will install/remove/update all the related packages that belongs to the group.
YUM Shell
Yum utility provides a custom shell where you can execute multiple commands.
yumdownloader
How do I use yum to download a package without installing it? There are multiple ways in which you can download a yum package without installing it. The 2 most commonly used methods are described here in the post.
using the “downloadonly” plugin for yum
using “yumdownloader” utility.
Method 1 : using the “downloadonly” plugin for yum:
First install the package including “downloadonly” plugin:
syntax:
If you do not use --downloaddir option, it would be saved in /var/cache/yum/ in rhel-{arch}-channel/packages directory.
example:
Method 2 : using the “yumdownloader” utility
First install the yum-utils package:
syntax:
example:
tryyumdownloader --help to see some of usefull switches such as :
the --resolve switch is usefull inorder to download a package ant its dependencies and lets us to use them in other system.
to view history of Yum commands (update, install, remove)
We can either use yum history command :
or see yum log file in /var/log/yum directory:
Summary
Fedora Family System:
Red Hat Package Manager (rpm):
low-level or underlying packet manager
Yellowdog Updater (yum):
The high-level package manager differs between distribution but yum is commonly used
Dandified Yum (dnf):
It is the next-generation version of yum
.
.
.
sources:
http://www.pepedocs.com/notes?tid=linux&nid=lfs101x#ch6
https://linux.die.net/man/8/rpm
https://www.tecmint.com/20-practical-examples-of-rpm-commands-in-linux/
http://ftp.rpm.org/max-rpm/s1-rpm-verify-output.html(rpm -V)
https://serverfault.com/questions/747089/whats-the-diff-between-rpm-u-and-rpm-f?rq=1
http://ftp.rpm.org/max-rpm/s1-rpm-erase-and-config-files.html
http://ftp.rpm.org/max-rpm/s1-rpm-miscellania-rpm2cpio.html
https://blog.packagecloud.io/eng/2015/10/13/inspect-extract-contents-rpm-packages/(what is inside rmp)
https://www.tecmint.com/20-linux-yum-yellowdog-updater-modified-commands-for-package-mangement/
https://www.quora.com/What-is-gpgcheck-in-a-yum-configuration-file-in-Rhel
https://superuser.com/questions/1252958/explanation-of-the-contents-inside-folder-etc-yum-repos-d
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/deployment_guide/sec-working_with_yum_cache( working with yum cache)
https://www.hivelocity.net/kb/how-to-clear-the-yum-cache/ (clear cache)
https://access.redhat.com/solutions/10154
.
Last updated
Was this helpful?