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 | root@attic‑f21 ~rpm ‑i gcc‑gfortran‑4.9.2‑6.fc21.x86_64.rpm |
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 | Loaded plugins: product-id, search-disabled-repos |
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 | # Base OS packages |
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 | yum update 'pop*' |
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 | [root@mycentctl1 ~]# rpm -q bind-utils |
Display info about a package:
1 | [root@mycentctl1 ~]# yum info bind-utils |
Search package names and descriptions for a term
1 | [root@mycentctl1 ~]# yum search vim |
RPM packages and files in them
List the files inside the package, you will see host
command is here:
1 | [root@mycentctl1 ~]# rpm -ql bind-utils |
if you have a download package and want to know the files in it, -p
means package:
1 | [root@mycentctl1 ~]# rpm -qlp jq-1.5-1.el7.x86_64.rpm |
Which package owns a file?
For YUM:
1 | yum provides vim |
For RPM:
1 | rpm -qf `which vim` |