What is Rpm? Rpm is package manager popular in Red Hat-based operating systems. Rpm full name is Red Hat Package Manager. Rpm uses rpm as package extension and format. Rpm packages are generally distributed from repositories on the internet but using USB, optical media or other ways is popular too in the old days. Yum is the online package manager used to get rpm packages from network or internet repositories.
Yum files are named like below with name, version, release, architecture.
As stated before repositories are used to hold rpm packages on the internet but also a CD can be used as a repository in rare situations. Repositories are used but yum/dnf commands.
Generally, Rpm packages are provided by repository and package managers like yum, dnf. But there are alternative sites that provide Rpm packages download manually.
Source code of packages is distributed with srpm packages. Srpm packages are zipped with tar.gz or tar.bz2
PatchRPM and DeltaRpm
Rpm packages provide some options to makes the download size smaller. Packages include a lot of different type of files. But not all files are changed. To makes packages smaller only changed files are distributed in Deltarpm’s.
Rpm packages have generally dependencies which means if we want to install some package we need to install other related packages before installing it. But We skip this and install some package with
$ rpm -ivh tmux-1.8-4.el7.x86_64.rpm
We need root privileges to install the rpm package. In our example, we tried to install tmux but as we see in message it is installed already.
As we know Rpm packages have dependencies which mean to install a package other packages may be needed. The needed packages must be installed before installing the current package. We can check dependencies like below.
rpm -qpR tmux-1.8-4.el7.x86_64.rpm
As we see tmux package depends on sh, standard C library, ncurses, Event library, etc.
Install Ignoring Dependency-Check
Normally if we try to install a package which has unmet dependency it will give error and do not installed. There is a way to install packages with unmet dependencies with forcefully. We will provide
--nodepsoption for installation.
$ rpm -ivh --nodeps tmux-1.8-4.el7.x86_64.rpm
Yum is used to downloading and installing automatically but in some cases, we may need to download package and install another system or etc. We can download an rpm package with a command named
yumdownloader like below. yumdownloader do not need any privilege for download operation.
$ yumdownloader tmux
We only provide a package name to the
Check Installed RPM Package
Rpm database holds information about installed packages. we can query this database like below. If the Rpm/application is installed the full package name is printed.
$ rpm -q tmux
List All Files Of Installed RPM Package
We may need to list files of and installed Rpm package. It is very similar to the checking process we will just add an
-lparameter like below.
$ rpm -ql tmux
List Recently Installed RPM Packages
We may want to list lastly installed Rpm packages. But keep in mind that will generate a lot of lines.
$ rpm -qa --last
I cannot put a screenshot here because it exceeds my terminal history. So I can put some limit or pagination to this list.
$ rpm -qa --last | less
As we can this will print the date of the RPM package installation with time information. In the screenshot for example
kdeadmin package installed 24 November at 09:50:33 .
List All Installed RPM Packages
Another way to list installed packages is to listing all packages not just latest installed.
$ rpm -qa
Using less in this situation is more practical. We can also search for command output with less.
$ rpm -qa | less
Upgrade RPM Packages
If an Rpm package is all ready installed we can upgrade existing package to a newer one. Advantage of the upgrade is that after upgrade old package is also held as a backup and if the new package does not work old package can be used.
rpm -Uvh tmux-1.8-4.el7.x86_64.rpm
Uninstall RPM Package
Uninstalling or erasing and Rpm package can be done with -e parameter like below.
$ rpm -evv tmux-1.8-4.el7.x86_64.rpm
Uninstall RPM Package Without Dependencies
We can only uninstall package itself and hold dependency packages in the system.
$ rpm -ev --nodeps tmux
An alternative way to remove Rpm package is not erasing dependencies.
Query File Name To Find Related RPM Package
Sometimes we need to find related Rpm package from a file name.
rpm -qf /bin/sh
Get Info About Installed RPM Package
We can get information about and installed Rpm package like name version, release, size, url, etc.
$ rpm -qi bash
Get Information About RPM Package
Actually Rpm provides a lot of important information about packages and its content. We can list and Rpm package information without installing it.
$ rpm -qip tmux-1.8-4.el7.x86_64.rpm
Query Documentation Of Installed RPM Package
Documentation of an installed Rpm package can get like below. It is similar to finding Rpm package name from a file.
$ rpm -qdf /bin/bash
Verify RPM Package
We can check and Rpm package and verify against the Rpm database. to verify -Vp parameters should be provided.
$ rpm -Vp tmux-1.8-4.el7.x86_64.rpm
Verify All RPM Packages
We can verify all installed Rpm packages. Verify process will look into the Rpm database to complete this job. Keep in mind that this will require a lot of time. We will use
--all for this operation.
$ rpm -Va
Import GPG Key Of RPM Package
GPG is a security protocol to verify authenticity. GPG is used recently to eliminate rouge repositories and Rpm packages but to benefit from this protocol GPG must be configured for Rpm. To configure GPG signs must be imported.
$ rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
List All Imported RPM GPG Keys
We can list existing or imported GPG keys like below.
$ rpm -qa gpg-pubkey*
As we can see from the screenshot that GPG keys have a different naming convention like
gpg-pubkey-GUID where GUID or UID is a unique identifier to prevent name collision.
Initialize RPM Database
If we want to create a new RPM database which will hold installed package information we can use the
--initdb option. This will create a new, empty, fresh database.
$ sudo rpm --initdb
Rebuild Corrupted RPM Database
Some time Rpm database can be get corrupted. Corrupted Rpm database can not be updated or used. So to get it into working condition Rpm database should be rebuilt like below.
$ cd /var/lib $ rm __db* $ rpm --rebuilddb $ rpmdb_verify Packages
Here we go the
/var/liband remove uncomplete database packages. Then run rpm rebuild command.
1 thought on “Linux RPM Command With Examples For CentOS, RedHat, Fedora”