rpm is a powerful package manager; here is a list of its basic command structure and common usage;


rpm has the following basic modes: query, verify, install, upgrade, freshen, reinstall, erase; these names match exactly to command options, so we have:

rpm --query {package_name}
rpm --verify {package_name}
rpm --install {package_file}
rpm --upgrade {package_file}
rpm --freshen {package_file}
rpm --reinstall {package_file}
rpm --erase {package_name}

straightforward enough; as a supplement, there are some shortcuts:

-q, --query
-V, --verify
-i, --install
-U, --upgrade
-F, --freshen
-e, --erase

unfortunately, --reinstall is an unlucky guy that does not own a shortcut;

as you can expect, --install installs a new package, and --erase erases an installed package; there are some nuances among --upgrade, --freshen and --reinstall, which can be found in its man page, however, most of the time what you want is --upgrade;

query mode

the most complicated mode is query; the general form of a query command is:

rpm {-q|--query} [select-options] [query-options]
  • select-options specifies which packages to select; this could be as simple as a package name; in addition to that, we can use -a to select all packages, -f to select packages owning files, and -p to select package files;

  • query-options specifies what information about the selected packages to display; the default is to display package fullnames (including version, release, arch, etc.); in addition to that, we have -i to display package info, -l to display package files, -R to display package dependencies;

below are some examples:

  • the simplest query command displays the package fullname:

    rpm -q gcc
  • the same command can display multiple packages (if there are):

    rpm -q kernel
  • use -a to query all installed packages:

    rpm -qa
  • the -a option can take a selector to narrow the selection:

    rpm -qa name="*gcc*"
  • omitting name= also works:

    rpm -qa "*gcc*"
  • match with multiple tags (undocumented?):

    rpm -qa name="*gcc*" version="1.2.3"
  • select packages owning a given file:

    rpm -qf /usr/bin/gcc
  • specifying multiple files works like specifying each one in turn:

    rpm -qf /usr/bin/gcc /usr/bin/bash
  • select a package file:

    rpm -qp ./gcc-1.1.1-1.fc11.x86_64.rpm
  • specifying multiple package files works like specifying each one in turn:

    rpm -qp ./gcc-1.1.1-1.fc11.x86_64.rpm ./bash-1.1.1-1.fc11.x86_64.rpm
  • use --whatrequires to select packages depending on the input:

    rpm -q --whatrequires gcc
  • use --whatprovides to select packages providing the input:

    rpm -q --whatprovides gcc
  • query package info:

    rpm -qi gcc
  • query package files:

    rpm -ql gcc
  • query package dependencies:

    rpm -qR gcc
  • in fact, -R is a shortcut of --requires:

    rpm -q --requires gcc
  • and yes, there is also --provides:

    rpm -q --provides gcc
  • select options and query options can be combined:

    rpm -qf /usr/bin/gcc -i
  • it seems mixing these options (even out of order) also works:

    rpm -qif /usr/bin/gcc
  • use option --qf to display formatted query:

    rpm -q --qf "%{name}\n" gcc
  • to list all installed packages and their sizes:

    rpm -qa --qf "%16{size} %{name}-%{epoch}:%{version}-%{release}.%{arch}\n"

    note that a tag may be displayed as (none) if missing; thus, this command does not guarantee the default nevra format;

http and ftp urls

where we provide a package file, we can instead provide a http or ftp url; rpm will handle the download; and we can use a proxy in both cases;