fbpx Red Hat Packages: rpm, yum, and dnf on CentOS and RHEL | Certificação Linux

Red Hat Package Management: rpm, yum, and dnf on CentOS and RHEL

📅 03/07/2019 ⏱ 15 min ✍️ Uira Ribeiro
Linuxcommandshow-to
Red Hat Package Management: rpm, yum, and dnf on CentOS and RHEL
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

The Red Hat Package Manager and YUM are powerful package managers that allow the administrator to install, remove, and obtain information about packages. It is a widely used software distribution method across various Linux distributions, such as Red Hat Enterprise Linux, CentOS, and Fedora.

Red Hat RPM Package Management and YUM make it possible to install packages, perform software updates, software groups, and dozens of other tasks. It is as powerful as dpkg and apt-get.

This package manager performs software package installation, maintenance, and removal in a simple way.

Each rpm package contains binary programs, configuration files, documentation, and information about how they should be installed and their dependencies.

This utility maintains a database of all installed packages and their files, version control, and dependencies.

In some special situations, the database may become corrupted. The package manager has special functions to recover its integrity.

RPM packages follow this naming convention:

  • Package_name: Just like Debian packages, an rpm package has a short name that describes its contents. If more than one word is used, a hyphen is used;
  • Software Version: Each rpm file has its version which may vary according to packages. It is usually numerical and is separated from the name by a hyphen;
  • Software Distribution: Each file may also have a different distribution or packaging;
  • Architecture: The rpm package usually carries the name of the architecture for which it was built;
  • Suffix: It uses the .rpm extension for easy identification.

We can also find packages with names in the format package-version.src.rpm. These packages contain the source files of a software and are for the most part architecture-independent.

The rpm package manager is used by several Linux distributions. But packages may differ in the additional information from one distribution to another. Always try to use packages specifically made for your distribution.

This package manager also handles dependency control between packages. They contain information about the dependencies of each application, and this information is used during its installation or removal.

If the installation of a new package requires another one, rpm will alert the administrator.

The rpm tool

The rpm command is responsible for installing, removing, updating, and converting packages. This command is organized first into operation modes, which can be: query, verification, integrity, installation, removal, upgrade, and rpm database rebuild. Each operation mode may or may not contain various available options.

The most frequently used operation modes are:

To query the rpm database

# rpm {-q|—query} [query-options] package-name

Example:

# rpm –q bash

bash-2.05b-207

To verify the status of packages with rpm

# rpm {-V|—verify} package-name

Example:

# rpm -V snort-2.0.1-98.i586.rpm

package snort-2.0.1-98.i586.rpm is not installed

To verify the signature and integrity of packages with rpm

# rpm {-K|—checksig} package-name

Example:

# rpm -K libpcap-0.7.2-37.i586.rpm

libpcap-0.7.2-37.i586.rpm: sha1 md5 gpg OK

To install a new package with rpm:

# rpm {-i|—install} [install-options] package-name

Example:

# rpm –i libpcap-0.7.2-37.i586.rpm

To install a new package showing installation details:

# rpm –ivh libpcap-0.7.2-37.i586.rpm

Preparing...                ########################################### [100%]

   1:libcap                 ########################################### [100%]

To upgrade a package with rpm:

# rpm {-U|—upgrade} [install-options] package-name

Example:

# rpm -U libpcap-0.7.2-37.i586.rpm

package libpcap-0.7.2-37 is already installed

To remove a package with rpm:

# rpm {-e|—erase} [remove-options] package-name

Example:

# rpm –e libpcap-0.7.2-37.i586.rpm

To rebuild the RPM database:

# rpm {—initdb|—rebuilddb}

Example:

# rpm —initdb

To query package dependencies with rpm:

# rpm {—qpR }

Example:

# rpm —qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm

/usr/bin/python2.4

python >= 2.3

python(abi) = 2.4

python-crypto >= 2.0

python-psyco

python-twisted >= 2.0

python-zopeinterface

rpmlib(CompressedFileNames) = 2.6

To install a package ignoring dependencies (a really stupid thing to do):

# rpm {—ivh --nodeps }

Example:

# rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm

Preparing...                ########################################### [100%]

   1:BitTorrent             ########################################### [100%]

To list recently installed rpm packages:

# rpm {—qa --last }

Example:

# rpm -qa --last

kernel-headers.x86_64     Sex 06 Mar 2019 11:55:01 BRT

graphviz-gd.x86_64         Sex 06 Mar 2019 11:55:00 BRT

file-devel.x86_64             Sex 06 Mar 2019 11:55:00 BRT

To find out which rpm package a file belongs to:

# rpm {—qf file }

Example:

# rpm -qf /usr/bin/htpasswd

httpd24-tools-2.4.10-15.58.amzn1.x86_64

To get information about a specific installed package:

# rpm {—qi package_name }

Example:

# rpm -qi httpd24

Name        : httpd24

Version     : 2.4.10

Release     : 15.58.amzn1

Architecture: x86_64

Install Date: Sex 13 Fev 2015 21:56:14 BRST

Group       : System Environment/Daemons

Size        : 3792099

To verify the integrity of installed files against the package database:

# rpm {—Va }

Example:

# rpm -Va

S.5....T.  c /etc/sysconfig/svnserve

....L....  c /etc/localtime

..?......    /usr/sbin/glibc_post_upgrade.x86_64

S.5....T.  c /etc/httpd/conf/httpd.conf

..?......    /usr/sbin/suexec

The most common package information query options are:

  • -a: Lists all packages installed on the system;
  • -f file: Lists the name of the package that contains the file being queried;
  • -p packagename: Shows if a specific package is installed;
  • -i packagename: Shows additional information about a specific package;
  • -l packagename: Shows the list of files contained in a package;
  • -R packagename: Shows the list of dependencies that a package needs to be installed.

The most common package installation and update options are:

  • —force: This option forces the installation of a package and its files even if it is already installed. This option even forces the installation of an older package over a newer one
  • -h: This option shows the installation progress;
  • —nodeps: This option disables dependency checking for package installation;
  • -v: Shows extra information during package installation and update;
  • -vv: Shows much more information during package installation and update. Usually used by developers.

The package uninstall options are:

  • —nodeps: Disables dependency checking, uninstalling the package even if it is required by others;
  • —test: Tests the package removal without actually removing it. It's useful for testing whether package removal will cause damage to the system or application.

When updating a package to a newer version, prefer using -U mode. This way, the older package will be removed, the new package will be installed, and the configurations will be kept.

YUM Tool

Yum stands for Yellow dog Updater, Modified. It's a tool used to manage package installation and removal on Linux distributions that use the RPM system.

It's a file package manager similar to APT-GET that automatically handles dependencies by computing them and resolving what needs to be done to address them.

It has a configuration file that specifies which repositories YUM should use to search for and download RPM packages.

Not every RPM-based Linux will have the YUM package manager installed. If it's necessary to install YUM, it can be obtained from the website http://yum.baseurl.org.

The installation command is:

# rpm -ivh yum.rpm

YUM requires you to configure package repositories in the yum.conf configuration file

Example:

# vi /etc/yum.conf

[fedora-us-3-core]

name=Fedora Core 3 — Fedora US mirror

baseurl=http://SERVERNAME/fedora/fedora/$releasever/$basearch/RPMS.os

[fedora-us-3-updates]

name=Fedora Core 3 Updates — Fedora US mirror

baseurl=http://SERVERNAME/fedora/fedora/$releasever/$basearch/RPMS.updates

In addition to the /etc/yum.conf configuration file, YUM allows you to place repository configuration files in the /etc/yum.repos.d/ directory. This directory contains the settings for each repository.

You can add extra or beta-testing software repositories to the YUM repository list.

Some yum commands:

  • yum list: Lists all available packages;
  • yum check-update or yum list updates: Checks if there are packages available for an update;
  • yum update: Updates your system;
  • yum install <package(s)>: Installs a specific package and its dependencies;
  • yum remove <package(s)>: Removes a specific package
  • yum info <package>: Displays basic information about a specific package.

See the examples:

To install a package with yum:

# yum install postgresql

Resolving Dependencies

Install       2 Package(s)

Is this ok [y/N]: y

Package(s) data still to download: 3.0 M

(1/2): postgresql-9.0.4-5.fc15.x86_64.rpm          | 2.8 MB     00:11

(2/2): postgresql-libs-9.0.4-5.fc15.x86_64.rpm    | 203 kB     00:00

------------------------------------------------------------------

Total                                        241 kB/s | 3.0 MB     00:12    

Running Transaction

  Installing : postgresql-libs-9.0.4-5.fc15.x86_64             1/2

  Installing : postgresql-9.0.4-5.fc15.x86_64                   2/2

Complete!

To update installed packages with yum:

# yum update

             Plugins loaded: priorities, update-motd, upgrade-helper

             amzn-main/latest

             Resolving Dependencies

             --> Running transaction check

             ---> Package aws-cli.noarch 0:1.7.5-1.2.amzn1 will be updated

             ---> Package aws-cli.noarch 0:1.7.12-1.3.amzn1 will be an update

             --> Dependency resolution finished

             Dependencies resolved

            ==============================================================

             Package    Arch               Version              Repo                Size

            ==============================================================

             Installing:

             kernel   x86_64     3.14.34-27.48.amzn1      amzn-updates          16 M

             Updating:

             aws-cli   noarch     1.7.12-1.3.amzn1          amzn-updates         604 k

             Transaction Summary

            ==============================================================                Install   1 Package  (+4 Dependent packages)

             Upgrade    1 Package

             Total download size: 16 M

             Is this ok [y/d/N]:

To remove a package with yum:

# yum remove  postgresql

Resolving Dependencies

---> Package postgresql.x86_64 0:9.0.4-5.fc15 will be erased

Is this ok [y/N]: y

Running Transaction

              Erasing    : postgresql-9.0.4-5.fc15.x86_64       1/1

Removed:

             postgresql.x86_64 0:9.0.4-5.fc15

Complete!

To search for all packages with a specific keyword

# yum search firefox

Loaded plugins: langpacks, presto, refresh-packagekit

============== N/S Matched: firefox ======================

firefox.x86_64 : Mozilla Firefox Web browser

gnome-do-plugins-firefox.x86_64 : gnome-do-plugins for firefox

mozilla-firetray-firefox.x86_64 : System tray extension for firefox

mozilla-adblockplus.noarch : Adblocking extension for Mozilla Firefox

mozilla-noscript.noarch : JavaScript list extension for Mozilla Firefox

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

To get information about a specific package using yum:

# yum info mysql

yum info mysql

Plugins loaded: priorities, update-motd, upgrade-helper

newrelic                                                                                                                                                                59/59

Installed Packages

Name        : mysql

Architecture        : noarch

Version     : 5.5

Release     : 1.6.amzn1

Size        : 0.0 

Repo        : installed

To see all packages available in the yum repository:

# yum list

Installed packages

GeoIP.x86_64                        1.4.8-1.5.amzn1                @amzn-main  

GeoIP-devel.x86_64                  1.4.8-1.5.amzn1                @amzn-main  

PyYAML.x86_64                       3.10-3.6.amzn1                 installed    

acl.x86_64                          2.2.49-6.9.amzn1               installed   

acpid.x86_64                        1.0.10-2.1.6.amzn1               installed   

alsa-lib.x86_64                     1.0.22-3.9.amzn1               installed   

apr.x86_64                          1.5.0-2.11.amzn1               @amzn-updates

(…)

To find which package a specific file belongs to:

# yum provides /etc/sysconfig/nfs

Loaded plugins: priorities, update-motd, upgrade-helper

1:nfs-utils-1.2.3-39.15.amzn1.x86_64 : NFS utilities and supporting clients and daemons for the kernel NFS server

Repo        : amzn-main

Result from:

File name    : /etc/sysconfig/nfs

To find out which repositories are active in YUM:

# yum repolist

repo id                         repo name          status

amzn-main/latest                  amzn-main-Base     5.019

amzn-updates/latest                          amzn-updates-Base  1.085

newrelic/x86_64                     New Relic packages 59

repolist: 6.163

The yumdownloader command

The yumdownloader command downloads RPM files from YUM repositories. It's useful for downloading packages for later installation, or when you're going to install packages on multiple machines, without the need to download the same package multiple times.

Example:

$ yumdownloader httpd24

amzn-main/latest                              | 2.1 kB     00:00    

amzn-updates/latest                           | 2.3 kB     00:00    

httpd24-2.4.10-15.58.amzn1.x86_64.rpm         | 1.3 MB     00:00

Learn Red Hat Enterprise Linux with the RHCSA Prep Course from Certificação Linux. If you already have an account, or want to create one, just log in or create your user here.

Like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp