fbpx rpm Command on Linux: Install and Manage RPM Packages | Certificação Linux

How to Use the rpm Command on Linux: Install, Remove, Query

📅 01/01/2019 ⏱ 5 min ✍️ Uira Ribeiro
Linuxcommands
How to Use the rpm Command on Linux: Install, Remove, Query
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 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 rebuilding. Each operation mode may or may not contain several available options.

The rpm is correlated to the dpkg of Debian, and also requires that each dependency be satisfied manually, as well as packages being downloaded manually. These commands are rarely used regarding package installation in distribution repositories, since the yum and apt are quite versatile, but they allow third-party packages to be installed manually.

The most frequent operation modes are:

To query the database

# rpm {-q|--query} [opções de consulta] nome_do_pacote

Example:

# rpm –q bash
bash-2.05b-207

To verify package status

# rpm {-V|--verify} nome_do_pacote

Example:

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

To verify package signature and integrity

# rpm {-K|--checksig} nome_do_pacote

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:

# rpm {-i|--install} [opções de instalação] nome_do_pacote

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:

# rpm {-U|--upgrade} [opções de instalação] nome_do_pacote

Example:

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

package libpcap-0.7.2-37 is already installed

To remove a package:

# rpm {-e|--erase} [opções de remoção] nome_do_pacote

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:

# 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 (something quite stupid 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 packages:

# rpm {—qa --last }

Example:

# rpm -qa --last
kernel-headers-3.14.34-27.48.amzn1.x86_64     Sex 06 Mar 2015 11:55:01 BRT
graphviz-gd-2.38.0-18.44.amzn1.x86_64         Sex 06 Mar 2015 11:55:00 BRT
file-devel-5.19-7.26.amzn1.x86_64             Sex 06 Mar 2015 11:55:00 BRT

To find out which package a file belongs to:

# rpm {—qf arquivo }

Example:

# rpm -qf /usr/bin/htpasswd
httpd24-tools-2.4.10-15.58.amzn1.x86_64

To find information about a specific installed package:

# rpm {—qi nome_do_pacote }

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
License     : ASL 2.0
Signature   : RSA/SHA256, Qui 12 Fev 2015 17:35:50 BRST, Key ID bcb4a85b21c0f39f
Source RPM  : httpd24-2.4.10-15.58.amzn1.src.rpm
Build Date  : Qui 12 Fev 2015 14:43:53 BRST
Build Host  : build-64003.build
Relocations : (not relocatable)
Packager    : Amazon.com, Inc. <http://aws.amazon.com>
Vendor      : Amazon.com
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible web server.

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 frequent package information query options are:

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

The most frequent package installation and upgrade options are:

  • --force: This option forces the installation of a package and its files even if it is already installed. This option also 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 upgrade;
  • -vv: Shows much more information during package installation and upgrade. Generally 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 is useful to test if the package removal will cause any damage to the system or application.

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

As you can see, the use of rpm is complicated at first glance, and not very practical, since the administrator needs to download packages and install dependencies manually. To make everything easier, RPM-based distributions adopted YUM.

Learn how to configure the Pfsense firewall in practice with the Pfsense Firewall Training from Certificação Linux! 

You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Did you 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