rpm command cheatsheet

This is a simple cheatsheet for the rpm command and can be used on systems like RedHat that uses the command

Syntax Description Example(s)
rpm -ivh {rpm-file} Install the package rpm -ivh sendmail-cf-8.14.2-1.fc8.rpm
rpm -ivh –test sendmail-8.14.2-1.fc8.rpm
rpm -Uvh {rpm-file} Upgrade package rpm -Uvh sendmail-cf-8.14.2-1.fc8.rpm
rpm -Uvh –test sendmail-8.14.2-1.fc8.rpm
rpm -ev {package} Erase/remove/ an installed package rpm -ev sendmail
rpm -ev –nodeps {package} Erase/remove/ an installed package without checking for dependencies rpm -ev –nodeps sendmail
rpm -qa Display list all installed packages rpm -qa
rpm -qa | less
rpm -qi {package} Display installed information along with package version and short description rpm -qi sendmail
rpm -ql {package-name} List files in package rpm -ql sendmail
rpm -qf {/path/to/file} Find out what package a file belongs to i.e. find what package owns the file rpm -qf /etc/passwd
rpm -qf /bin/bash
rpm -qc {pacakge-name} Display list of configuration file(s) for a package rpm -qc httpd
rpm -qcf {/path/to/file} Display list of configuration files for a command rpm -qcf /usr/bin/locate
rpm -qa –last Display list of all recently installed RPMs rpm -qa –last
rpm -qa –last | less
rpm -qpR {.rpm-file}
rpm -qR {package}
Find out what dependencies a rpm file has rpm -qpR sendmail-8.14.2-1.fc8.rpm
rpm -qR bash
rpm –test {package} Perform Installation Tests Only rpm -i –test rpm-2.0.11-1.i386.rpm
/bin/rpm conflicts with file from rpm-2.3-1
/usr/bin/gendiff conflicts with file from rpm-2.3-1
/usr/bin/rpm2cpio conflicts with file from rpm-2.3-1
/usr/bin/rpmconvert conflicts with file from rpm-2.3-1
/usr/man/man8/rpm.8 conflicts with file from rpm-2.3-1
error: rpm-2.0.11-1.i386.rpm cannot be installed
rpm –replacepkgs Install the Package Even If Already Installed. Is used to force RPM to install a package that it believes to be installed already. This option is normally used if the installed package has been damaged somehow and needs to be fixed up.

{package} – Replace with actual package name

List rpm package content

To list the contents of a package just run the command

# rpm -ql packagename

Example

# rpm -ql nmap

/usr/bin/nmap
/usr/share/doc/nmap-3.70
/usr/share/doc/nmap-3.70/COPYING
/usr/share/doc/nmap-3.70/COPYING.OpenSSL
/usr/share/doc/nmap-3.70/README
/usr/share/doc/nmap-3.70/nmap-fingerprinting-article.txt
/usr/share/doc/nmap-3.70/nmap.deprecated.txt
/usr/share/doc/nmap-3.70/nmap.usage.txt
/usr/share/doc/nmap-3.70/nmap_doc.html
/usr/share/doc/nmap-3.70/nmap_manpage.html
/usr/share/man/man1/nmap.1.gz
/usr/share/nmap
/usr/share/nmap/nmap-mac-prefixes
/usr/share/nmap/nmap-os-fingerprints
/usr/share/nmap/nmap-protocols
/usr/share/nmap/nmap-rpc
/usr/share/nmap/nmap-service-probes
/usr/share/nmap/nmap-services

Upgrade from Fedora Core 7 to Core 8

This is the steps I took to upgrade a running Fedora Core 7 installation to Core 8 using yum from the command line. Please note that live upgrades are not recommended by the Fedora Project.

Make a list of the systems current packages for later reference:

rpm -qa --qf '%{NAME}\n' | sort | uniq > ~/new-pkgnames.txt

Make a backup of any system configuration data (as root):

tar czf ~/etc-`date +%F`.tar.gz /etc


yum clean all

Make sure the new repo files isn’t placed as .rpmnew files, perhaps by

mv /etc/yum.repos.d/fedora-updates.repo.rpmnew /etc/yum.repos.d/fedora-updates.repo
mv /etc/yum.repos.d/fedora.repo.rpmnew /etc/yum.repos.d/fedora.repo

Also make sure that all the 3rd party repos you normally use point to the repository for the new Fedora release.

Next the upgrade.
Make sure you are in runlevel 3

telinit 3

Run the following command to update the yum repo on your box:

rpm -Uhv rpm -Uvh rpm -Uvh http://mirror.anl.gov/pub/fedora/linux/releases/8/Everything/i386/os/Packages/fedora-release-8-3.noarch.rpm http://mirror.anl.gov/pub/fedora/linux/releases/8/Everything/i386/os/Packages/fedora-release-notes-8.0.0-3.noarch.rpm

yum might complain about conflicts or requirements. That is probably because you have used non-standard repositories or installed non-standard packages manually. Try to guess which packages cause the problem (or at least is a part of the dependency chain) – uninstall them and try again. Remember to install the packages again if they are essential.

Tip: Find and review “lost” packages.
You can find orphaned packages (ie packages not in the repositories anymore) after the upgrade with the tool package-cleanup from the yum-utils package

yum install yum-utils; package-cleanup --orphans

It’s often helpful to run this command before the update, too. For packages with a failing “%postun” script the old package will remain partly installed. Remove it with

rpm -e package-name-and-version

If you forget to remove the avahi package it will refuse to be removed from the system with a error message “error: %postun(avahi-0.6.17-1.fc7.i386) scriptlet failed, exit status 1”. I haven’t looked up this error message any further.

I had to clean yum to make it aware of the recent package change, this might not be necessary.

yum clean all
yum upgrade

Ensure that all (new) essential packages from the new version is installed with

yum groupupdate Base

You might want to update other groups too, see

yum grouplist

The system had to upgrade 937 packages before fedora Core 7 is a fedora Core 8 installation.

After the upgrade has finished a reboot is required and it was time to check for orphaned packages

package-cleanup --orphans

The command for removing these packages is described earlier.

Source: http://docs.fedoraproject.org/install-guide/f8/en_US/sn-upgrade-tree.html, http://www.ioncannon.net/system-administration/133/upgrading-from-fedora-7-to-fedora-8-with-yum/ and http://fedoraproject.org/wiki/YumUpgradeFaq

Remove duplicate packages when querying the rpm database

Today I had to solve a RPM problem on a Red Hat Enterprise Linux WS release 4 (Nahant Update 6) system (RHEL4) where there were duplicate packages when querying the rpm database. This had happened after an upgrade to update 6 using up2date from the command line.

It seemed like i386 and x64 packages had gotten installed on some packages and this caused some problems, like logon authentication and execution of some programs.

Trying to remove a duplicate rpm package

# rpm -e libtool-libs-1.5.6-4.El4.2

gave the error message

error: "libtool-libs-1.5.6-4.El4.2" specifies multiple packages

After searching the Red Hat knowledge base I located article Why do I see duplicate packages when querying the rpm database? where it says it is necessary to specify the architecture of the package to remove.

# rpm -qa --queryformat %{NAME}-%{VERSION}-%{ARCH}\\n

If you add %{RELEASE} you can also determine if the package is from other package vendors like RPMForge.

Since this was a x64 system, I wanted to remove the i386 version

# rpm -e libtool-libs-1.5.6-4.El4.2.i386

This had to be done with every duplicate package on the system.
Locate the i386 packages that interfered with the x64 packages can be done using the command

rpm -qa | sort | uniq -d

These packages have dependencies so you have to add these manually, really fun job to do.

Edit:
In RHEL5 you can use yum to remove packages in a easy way

yum remove <package>.i386
yum remove <package>.x86_64