LPI Linux Certification/Use RPM and YUM package management

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.

Detailed Objective

edit

(LPIC-1 Version 5.0)

Weight: 3

Description:
Candidates should be able to perform package management using RPM, YUM and Zypper.

Key Knowledge Areas:

  • Install, re-install, upgrade and remove packages using RPM, YUM and Zypper.
  • 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.
  • Awareness of dnf.

The following is a partial list of the used files, terms and utilities:

  • rpm
  • rpm2cpio
  • /etc/yum.conf
  • /etc/yum.repos.d/
  • yum
  • zypper

Red Hat Package Manager

edit

Some Linux distribution uses rpm the “Red Hat Package Manager” for all its distribution software. RPM maintains a detailed database of all software installed in the system.

To install a RPM package, do:

rpm -i [package].rpm

The package will be installed only if the dependency are met and there is no conflict with another package. To upgrade a package, do:

rpm -U [package].rpm

The files of the old package version will be removed and replaced by the new files. To remove a RPM package, do:

rpm -e [package].rpm

The package will be removed only if no other package depends on it.

RPM Queries

edit

With the -q option you can query the RPM database or display information about package file.

There are several switches that you can use:

  • -i: to get package information
rpm -q -i apache
  • -l: To get a file list of a package.
$ rpm -q -l pciutils
/sbin/lspci
/sbin/setpci
/usr/share/doc/package/pciutils
...
/usr/share/pci.ids
  • -f file: Query which package a file belongs to.
$ rpm -q -f /sbin/lspci
pciutils-2.1.9-58
  • -s: File list with status information.
  • -d: list only documentation files.
  • -a: List all the installed packages.

If you want to display information about package file you can specify filename using -p switch:

rpm -q -i -p [package].rpm

RPM Commands

edit

To get general information on a package or program, use rpmlocate.

rpmlocate ipcs -q -i apache

Searching for ipcs in rpm db:

util-linux-2.11n-75:
/usr/bin/ipcs
/usr/share/man/man8/ipcs.8.gz

To list all the installed packages, use rpmqpack:

rpmqpack

Alternatively use:

rpm -qa


Source Installation

edit

The RPM source files have generally the format package.src.rpm and can be installed the same way as binaries. The directories where they will be installed from /usr/src/packages are:

  • SOURCES: For the original sources.
  • SPECS: For the .spec file that controls the build process.
  • BUILD: All the sources are built in this directory.
  • RPMS: Where the complete binary packages are stored.
  • SRPMS: The sources.

To install the source of a package, do:

$ rpm -i mypack.src.rpm

The source files will be stored in the /usr/src/packages in directories SPEC and SOURCES. To compile the sources, do:

$ rpm -ba /usr/src/packages/SPECS/mypack.spec

The result of the compilation will be stored in the BUILD directory

Exercises

edit
  1. Is the apache package installed?
  2. In which package are the files /bin/ls, /usr/sbin/tcpdump, and /sbin/ifconfig?
  3. From the floppy disk install the pci utilities and grub packages. Build the binaries and try to execute them. The sources should be in the /usr/src/packages/BINARY directory.