Yum and Rpm Management 101

OK, This article is a summary from IBM developer Linux series that contains something I haven’t realized and history information about YUM and RPM.

Introducing package management

In the past, many Linux programs were distributed as source code, which a user would build into the required program or set of programs, along with the required man pages, configuration files, and so on. Nowadays, most Linux distributors use prebuilt programs or sets of programs called packages, which ship ready for installation on that distribution. In this tutorial, you will learn about package management tools that help you install, update, and remove packages. This tutorial focuses on the Red Hat Package Manager (RPM), which was developed by Red Hat, as well as the Yellowdog Updater Modified (YUM), which was originally developed to manage Red Hat Linux systems at Duke University’s Physics department. Another tutorial in this series, “Learn Linux 101: Debian package management,” covers the package management tools used on Debian systems.

Package managers

RPM, YUM, and APT (for Debian systems) have many similarities. All can install and remove packages. Information about installed packages is kept in a database. All have basic command-line functionality, while additional tools can provide more user-friendly interfaces. All can retrieve packages from the Internet.

When you install a Linux system, you typically install a large selection of packages. The set may be customized to the intended use of the system, such as a server, desktop, or developer workstation. And at some time you will probably need to install new packages for added functionality, update the packages you have, or even remove packages that you no longer need or that have been made obsolete by newer packages. Let’s look at how you do these tasks, and at some of the related challenges such as finding which package might contain a particular command.

RPM

Red Hat introduced RPM in 1995. RPM is now the package management system used for packaging in the Linux Standard Base (LSB). The rpm command options are grouped into three subgroups for:

  • Querying and verifying packages
  • Installing, upgrading, and removing packages
  • Performing miscellaneous functions

YUM

YUM adds automatic updates and package management, including dependency management, to RPM systems. In addition to understanding the installed packages on a system, YUM is like the Debian Advanced Packaging Tool (APT) in that it works with repositories, which are collections of packages and are typically accessible over a network connection.

Install RPM packages

1
2
3
root@attic‑f21 ~rpm ‑i  gcc‑gfortran‑4.9.2‑6.fc21.x86_64.rpm 
error: Failed dependencies:
libquadmath‑devel = 4.9.2‑6.fc21 is needed by gcc‑gfortran‑4.9.2‑6.fc21.x86_64

One good thing is that you can give the rpm command a list of packages to install and it will install them all in the right order if all dependencies are satisfied. So you at least don’t have to manually install each piece in the right order.

What is the difference between i686 and x86_64 packages? Technically, i686 is actually a 32-bit instruction set (part of the x86 family line), while x86_64 is a 64-bit instruction set (also referred to as amd64).

let’s see the yum install output in my machine:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Loaded plugins: product-id, search-disabled-repos
Local-Base | 2.0 kB 00:00:00
Local-Extras | 2.9 kB 00:00:00
Local-Optional | 2.0 kB 00:00:00
Local-Supplementary | 2.0 kB 00:00:00
(1/6): Local-Base/updateinfo | 3.2 MB 00:00:00
(2/6): Local-Supplementary/primary | 99 kB 00:00:00
(3/6): Local-Optional/updateinfo | 2.3 MB 00:00:00
(4/6): Local-Optional/primary | 5.0 MB 00:00:00
(5/6): Local-Supplementary/updateinfo | 69 kB 00:00:00
(6/6): Local-Base/primary | 34 MB 00:00:00
Local-Base 23907/23907
Local-Optional 17526/17526
Local-Supplementary 310/310
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.160-5.el7 will be installed
--> Processing Dependency: vim-common = 2:7.4.160-5.el7 for package: 2:vim-enhanced-7.4.160-5.el7.x86_64
--> Processing Dependency: libgpm.so.2()(64bit) for package: 2:vim-enhanced-7.4.160-5.el7.x86_64
--> Running transaction check
---> Package gpm-libs.x86_64 0:1.20.7-5.el7 will be installed
---> Package vim-common.x86_64 2:7.4.160-5.el7 will be installed
--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.160-5.el7.x86_64
--> Running transaction check
---> Package vim-filesystem.x86_64 2:7.4.160-5.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved

=================================================================================================================
Package Arch Version Repository Size
=================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.160-5.el7 Local-Base 1.0 M
Installing for dependencies:
gpm-libs x86_64 1.20.7-5.el7 Local-Base 32 k
vim-common x86_64 2:7.4.160-5.el7 Local-Base 5.9 M
vim-filesystem x86_64 2:7.4.160-5.el7 Local-Base 10 k

Transaction Summary
=================================================================================================================
Install 1 Package (+3 Dependent packages)

Total download size: 7.0 M
Installed size: 23 M

Is this ok [y/d/N]: y
Downloading packages:
(1/4): gpm-libs-1.20.7-5.el7.x86_64.rpm | 32 kB 00:00:00
(2/4): vim-enhanced-7.4.160-5.el7.x86_64.rpm | 1.0 MB 00:00:00
(3/4): vim-filesystem-7.4.160-5.el7.x86_64.rpm | 10 kB 00:00:00
(4/4): vim-common-7.4.160-5.el7.x86_64.rpm | 5.9 MB 00:00:00
-----------------------------------------------------------------------------------------------------------------
Total 55 MB/s | 7.0 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
mokutil-15-1.el7.x86_64 is a duplicate with mokutil-12-1.el7.x86_64
Installing : gpm-libs-1.20.7-5.el7.x86_64 1/4
Installing : 2:vim-filesystem-7.4.160-5.el7.x86_64 2/4
Installing : 2:vim-common-7.4.160-5.el7.x86_64 3/4
Installing : 2:vim-enhanced-7.4.160-5.el7.x86_64 4/4
Local-Base/productid | 2.1 kB 00:00:00
Local-Supplementary/productid | 2.1 kB 00:00:00
Verifying : 2:vim-enhanced-7.4.160-5.el7.x86_64 1/4
Verifying : 2:vim-common-7.4.160-5.el7.x86_64 2/4
Verifying : 2:vim-filesystem-7.4.160-5.el7.x86_64 3/4
Verifying : gpm-libs-1.20.7-5.el7.x86_64 4/4

Installed:
vim-enhanced.x86_64 2:7.4.160-5.el7

Dependency Installed:
gpm-libs.x86_64 0:1.20.7-5.el7 vim-common.x86_64 2:7.4.160-5.el7 vim-filesystem.x86_64 2:7.4.160-5.el7

Complete!

Here we see yum find x86_64 version of vim in Local-Base repository. Sometimes you will usually want the latest version of a package, but you can provide additional qualifications if you need an earlier version, or the i686 version instead of the x86_64 version. See the section on specifying package names in the man pages for the yum command.

Package locations

Where do the packages come from? How does yum know where to download packages from? The starting point is the /etc/yum.repos.d/ directory, which usually contains several repo files. This is the default location for repository information, but other locations may be specified in the YUM configuration file, normally /etc/yum.conf.

In the Fyre machine, there is a devit-rh7-x86_64.repo file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Base OS packages
[Local-Base]
name=Fyre Local OS repository
baseurl=http://fyreyum1.fyre.ibm.com/redhat/yum/server/7/7Server/x86_64/os
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
gpgcheck=1
enabled=1

[Local-Supplementary]
name=Fyre Local Supplementary repository
baseurl=http://fyreyum1.fyre.ibm.com/redhat/yum/server/7/7Server/x86_64/supplementary/os
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
gpgcheck=1
enabled=1

[Local-Optional]
name=Fyre Local Optional repository
baseurl=http://fyreyum1.fyre.ibm.com/redhat/yum/server/7/7Server/x86_64/optional/os
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
gpgcheck=1
enabled=1

[Local-Extras]
name=Fyre Local Extras repository
baseurl=http://fyreyum1.fyre.ibm.com/redhat/yum/server/7/7Server/x86_64/extras/os
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
gpgcheck=1
enabled=1

YUM and RPM use a local database to determine what packages are installed. The metadata about packages that is stored in the local database is retrieved from the enabled repositories. Although you will seldom need to worry about the local database, you use the command yum clean all to clean out various parts of the locally stored information and yum makecache to create the information in your local database for the enabled repos. You might do this if you change your repo configuration, for example.

Removing RPM packages

The RPM system does not maintain information on packages that were automatically added, so there is no trivial way to find out which dependencies might also be removed.

If you use YUM and if the package you are trying to remove is a dependent package for some other installed packages, then YUM will offer to remove those as well as the dependent package. (This is different from yum autoremove)

Upgrading RPM packages

You can use yum update to update your entire system, or you can specify a single package or a wildcard specification. Listing 8 shows how to update all the packages whose names start with “pop”. Note the use of apostrophes to prevent shell expansion of the “*”.

1
2
yum update 'pop*'
yum update elasticsearch-7.10.2

what is the difference between yum update and yum upgrade? yum upgrade forces the removal of obsolete packages, while yum update may or may not also do this. The removal of obsolete packages can be risky, as it may remove packages that you use. This makes yum update the safer option.

Querying RPM packages

In our examples you saw that installing an rpm with the rpm command requires the full name of the package file (or URL), such as gcc-gfortran-4.9.2-6.fc21.x8664.rpm. On the other hand, installing with yum, or removing an rpm with either command requires only the package name, such as gcc-gfortran. As with APT, YUM maintains an internal database of your installed packages, allowing you to manipulate installed packages using the package name.

Note that you need to have root authority to install, upgrade, or remove packages, but non-root users can perform queries against the rpm database.

Basic query asks if package is installed, if so, show version number:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@mycentctl1 ~]# rpm -q bind-utils
bind-utils-9.9.4-73.el7_6.x86_64

[root@mycentctl1 ~]# rpm -q ansible
package ansible is not installed

[root@mycentctl1 ~]# yum list bind-utils
Loaded plugins: product-id, search-disabled-repos
Installed Packages
bind-utils.x86_64 32:9.9.4-73.el7_6 @Local-Base

[root@mycentctl1 ~]# yum list ansible
Loaded plugins: product-id, search-disabled-repos
Available Packages
ansible.noarch 2.4.2.0-2.el7 Local-Extras

Display info about a package:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@mycentctl1 ~]# yum info bind-utils
Loaded plugins: product-id, search-disabled-repos
Installed Packages
Name : bind-utils
Arch : x86_64
Epoch : 32
Version : 9.9.4
Release : 73.el7_6
Size : 431 k
Repo : installed
From repo : Local-Base
Summary : Utilities for querying DNS name servers
URL : http://www.isc.org/products/BIND/
License : ISC
Description : Bind-utils contains a collection of utilities for querying DNS (Domain
: Name System) name servers to find out information about Internet
: hosts. These tools will provide you with the IP addresses for given
: host names, as well as other information about registered domains and
: network addresses.
:
: You should install bind-utils if you need to get information from DNS name
: servers.

Search package names and descriptions for a term

1
2
3
4
5
6
7
8
9
10
11
12
[root@mycentctl1 ~]# yum search vim
Loaded plugins: product-id, search-disabled-repos
================================================= N/S matched: vim ==================================================
golang-vim.noarch : Vim plugins for Go
protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-filesystem.x86_64 : VIM filesystem layout
vim-minimal.x86_64 : A minimal version of the VIM editor

Name and summary matches only, use "search all" for everything.

RPM packages and files in them

List the files inside the package, you will see host command is here:

1
2
3
4
5
6
7
8
9
10
[root@mycentctl1 ~]# rpm -ql bind-utils
/etc/trusted-key.key
/usr/bin/dig
/usr/bin/host
/usr/bin/nslookup
/usr/bin/nsupdate
/usr/share/man/man1/dig.1.gz
/usr/share/man/man1/host.1.gz
/usr/share/man/man1/nslookup.1.gz
/usr/share/man/man1/nsupdate.1.gz

if you have a download package and want to know the files in it, -p means package:

1
2
3
4
5
6
7
8
9
10
[root@mycentctl1 ~]# rpm -qlp jq-1.5-1.el7.x86_64.rpm
warning: jq-1.5-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
/usr/bin/jq
/usr/lib64/libjq.so.1
/usr/lib64/libjq.so.1.0.4
/usr/share/doc/jq/AUTHORS
/usr/share/doc/jq/COPYING
/usr/share/doc/jq/README
/usr/share/doc/jq/README.md
/usr/share/man/man1/jq.1.gz

Which package owns a file?

For YUM:

1
yum provides vim

For RPM:

1
rpm -qf `which vim`
0%