Frequently Asked Question

What lives in /var/lib/dpkg and /var/lib/rpm?

Both directories are the installed-package database, the package manager's local record of what is on this machine, which files belong to which package, what version they are, and which scripts have run. /var/lib/dpkg/ contains plain text files: status (one stanza per installed package, the master record), info/<pkg>.list (every file the package owns), info/<pkg>.md5sums (checksums for verification), and info/<pkg>.{preinst,postinst,prerm,postrm} (the maintainer scripts). You can read it with cat, which is why dpkg-query and dpkg -L are fast.

/var/lib/rpm/ is a binary database, historically Berkeley DB, sqlite on modern RHEL and Fedora, that rpm queries with its own schema. The information stored is the same in kind (files, checksums, dependencies, scripts), but you cannot just grep it; you use rpm -qa, rpm -ql, rpm -qf, and so on. Both databases are precious: if they are corrupted the package manager loses its memory of what is installed. Back them up, and never edit them by hand.

Further reading and video