Direct Answer / TL;DR
The rpm macro stack resolves %_dbpath (RHEL 9: /var/lib/rpm; Fedora/RHEL 10: /usr/lib/sysimage/rpm) to an empty string or a missing directory, so openDatabase() aborts. Recreate the directory, remove stale BerkeleyDB __db.* locks, run sudo rpm --rebuilddb — or rpm --initdb if empty — on Ubuntu 24.04, Debian 12, and RHEL 9.
sudo rpm --rebuilddb
error: no dbpath has been set CRITICAL:yum.main: Error: rpmdb open failed
Symptom & Exact Error Signature
The error fires the moment any rpm-linked tool — legacy yum, dnf, rpm, rpmdb, PackageKit, or a CI stage calling librpm — reaches openDatabase() and the %_dbpath macro resolves to an empty string, or to a directory that does not exist on the effective root (host, --root chroot, --installroot, container image). Every rpmdb open path then aborts with this signature and exit status 1:
$ sudo yum list installed
error: no dbpath has been set
CRITICAL:yum.main:
Error: rpmdb open failed
$ sudo rpm -qa
error: no dbpath has been set
$ echo $?
1
# dnf on RHEL 8/9 surfaces the same librpm failure as:
Error: rpmdb open failed
You typically meet it in chroot rescue from a live ISO, dnf --installroot/yum --installroot rootfs staging, disaster recovery after /var was lost, or container images whose rpmdb directory was deleted in a build stage.
Root Cause Breakdown
rpm does not hardcode its database location in its decision logic; every openDatabase() call walks the macro stack — compiled default → /usr/lib/rpm/macros → /usr/lib/rpm/macros.d/*.conf → /etc/rpm/macros, /etc/rpm/macros.<arch>, /etc/rpm/macros.image → ~/.rpmmacros → CLI --define/--dbpath — and evaluates %_dbpath. If the result is empty or the target directory is absent, rpmlog() writes no dbpath has been set to stderr and the process exits 1 before any BerkeleyDB, sqlite, or ndb handle is created. Three trigger classes:
- Blank macro override: a leftover
%_dbpathline in/etc/rpm/macros,/etc/rpm/macros.image, or/root/.rpmmacrosthat expands to nothing; provisioning scripts, image builders, and Ansible tasks that “cleaned” rpm macros are common culprits. - Directory wiped:
/var/lib/rpm(RHEL 9, Alma/Rocky 9, Debian 12, Ubuntu 24.04 rpm builds) or/usr/lib/sysimage/rpm(Fedora 34+, RHEL 10, openSUSE — where/var/lib/rpmis usually a compatibility symlink) was deleted: a failed/varmount, cleanup in a container stage, or--installroot/--rootpointed at a rootfs that has no rpmdb yet. - Foreign-root evaluation: with
rpm --rootoryum --installroot, dbpath is resolved inside the target tree; a freshly extracted or debootstrap-style rootfs withoutvar/lib/rpmreproduces the error even though the host database is healthy.
Sibling failure to distinguish: when the BerkeleyDB environment locks __db.001–__db.003 survive a SIGKILL‘d rpm/dnf/PackageKit, dbpath prints correctly and you instead get db5 error(-30973) ... DB_RUNRECOVERY. The sequence below covers both, because they co-occur after crashes. journalctl shows identical lines for unattended runs: journalctl -g 'no dbpath' or journalctl -u dnf-makecache.service.
Step-by-Step Diagnostic & Fix Sequence
- Verify the state: resolve the effective dbpath and inspect its contents. An empty expansion or a “No such file or directory” is the smoking gun.
$ rpm -E '%_dbpath' /var/lib/rpm $ dbp="$(rpm -E '%_dbpath')"; ls -la "$dbp" 2>&1 | head $ rpm -E '%_db_backend' bdb $ grep -Rns '%_dbpath' /etc/rpm /usr/lib/rpm/macros.d 2>/dev/null; grep -ns '_dbpath' /root/.rpmmacros 2>/dev/nullExpected stdout: a real path; a directory containing
Packages/Packages.db(bdb),rpmdb.sqlite(sqlite), orrpmdb.ndb(ndb) plus the__db.*env locks; a backend string matching the host packaging stack; and zero blank%_dbpathoverride lines in the grep output. - Apply the fix: quiesce concurrent package managers, take a byte-for-byte backup, then rebuild or initialize. Run as root; adapt paths from the matrix below:
sudo systemctl stop packagekit dnf-makecache.timer 2>/dev/null || true sudo cp -a /var/lib/rpm /var/lib/rpm.bak-$(date +%F-%H%M) && sudo ls /var/lib/rpm.bak-*/Packages | head # Case A - directory exists, stale BDB env locks / crashed session: sudo find /var/lib/rpm -maxdepth 1 -name '__db.*' -print # dry-run before the rm sudo rm -f /var/lib/rpm/__db.* sudo rpm --rebuilddb # Case B - directory missing or empty (rootfs, container, installroot): sudo mkdir -p /var/lib/rpm && sudo rpm --initdb # --root targets: mkdir -p /mnt/root/var/lib/rpm && rpm --root /mnt/root --initdb sudo restorecon -Rv /var/lib/rpm 2>/dev/null # SELinux enforcing hosts onlyIf the grep found a blank
%_dbpathline, delete or comment it in/etc/rpm/macros,/etc/rpm/macros.image, or/root/.rpmmacros, then re-checkrpm -E '%_dbpath'before rebuilding. An--initdbdatabase is legitimately empty at zero packages; repopulate headers without touching payloads from any available RPM set withrpm -Uvh --justdb --noscripts --notriggers /var/cache/dnf/*/packages/*.rpm(or packages from your ISO mirror), which reconstructs the installed-package list. - Confirm resolution:
$ rpm -qa | wc -l 1043 $ sudo dnf makecache ... Metadata cache created. $ sudo rpm -V setup && echo OK OKExpected: a package count consistent with the host (RHEL 9 minimal container ≈ 250+, full install ≈ 1000+, 0 on a fresh
--initdbroot),dnf makecachecompleting cleanly, andrpm -V setupexiting 0. On legacy yum systems,yum check-updatereturning exit 0 (no updates) or 100 (updates available) confirms the database is fully queryable.
Multi-Distro Command & Path Matrix
Ubuntu / Debian
# Ubuntu 24.04 / Debian 12: rpm 4.18 is cross-tooling only; APT/dpkg untouched. No dnf/yum installed.
sudo apt install -y rpm
rpm -E '%_dbpath' # -> /var/lib/rpm
sudo mkdir -p /var/lib/rpm && sudo rpm --initdb # silent = success
sudo rpm --root /mnt/guest --dbpath /var/lib/rpm -qa | head # operate on a foreign RPM rootfs
RHEL / AlmaLinux / Rocky
# RHEL 9 / Alma 9: bdb backend in /var/lib/rpm | RHEL 10: /usr/lib/sysimage/rpm
rpm -E '%_dbpath' && rpm -E '%_db_backend'
sudo cp -a /var/lib/rpm /var/lib/rpm.bak-$(date +%F-%H%M)
sudo find /var/lib/rpm -maxdepth 1 -name '__db.*' -print # dry-run
sudo rm -f /var/lib/rpm/__db.* && sudo rpm --rebuilddb
sudo rpm -qa | wc -l
# On RHEL 10, substitute $(rpm -E '%_dbpath') for the directory in every line above
Arch Linux
# Arch manages packages with pacman; no host rpmdb exists and rpm is not in official repos.
pacman -Qq pacman
# Repair a foreign RPM rootfs through a throwaway RHEL container:
docker run --rm -v /var/tmp/rhel9-rootfs:/rootfs almalinux:9
sh -c 'mkdir -p /rootfs/var/lib/rpm && rpm --root /rootfs --initdb && rpm --root /rootfs -qa | head'
Alpine / Containers
# Alpine's system packages are apk-managed; run rpm tooling inside an RPM distro image:
docker run --rm -v /srv/rhel9-rootfs:/rootfs almalinux:9
sh -c 'rpm -E "%_dbpath" && ls -la /rootfs/var/lib/rpm && rpm --root /rootfs -qa | head'
# CI note: the error re-appears every build if a stage deleted /var/lib/rpm —
# recreate with mkdir -p /var/lib/rpm && rpm --initdb before any rpm/dnf call.
Safety & Rollback Checks
Safety Check: The only destructive steps are deleting BDB environment locks and swapping the db directory — both are gated:
- Dry-run the deletion and confirm only
__db.*lock files match:sudo find /var/lib/rpm -maxdepth 1 -name '__db.*' -print. Never removePackages,Packages.db,rpmdb.sqlite, orrpmdb.ndb— those hold every installed-package header and are unrecoverable without--justdbreconstruction. - Verify the backup before touching anything:
sudo du -sh /var/lib/rpm.bak-* && sudo ls /var/lib/rpm.bak-*/Packages | head.cp -apreserves ownership, modes, and SELinux xattrs. - Rollback:
sudo mv /var/lib/rpm /var/lib/rpm.broken && sudo mv /var/lib/rpm.bak-<stamp> /var/lib/rpm && sudo restorecon -Rv /var/lib/rpm. - Never run
rpm --rebuilddbwhilednf, PackageKit, or another rpm process holds the db open — a mid-rewrite kill truncates header files; thesystemctl stopstep exists for this reason. - On ndb or sqlite backends,
--rebuilddbsemantics differ; if the command errors about the backend, restore the backup instead of forcing a rebuild. - Macro edits have no
-tsyntax test;rpm -E '%_dbpath'is the test — re-run it after every change and expect a full path, not an empty line.
Frequently Asked Edge Cases
Where is the RPM database on Fedora 41 or RHEL 10?
At /usr/lib/sysimage/rpm after the rpm 4.16+ relocation (/var/lib/rpm becomes a compatibility symlink). Verify with rpm -E '%_dbpath'; the same recovery sequence applies after backing up that directory.
Why does this error reappear in every Docker/CI build?
A build stage that deleted /var/lib/rpm (or a bare dnf in a rootfs with no rpmdb) leaves %_dbpath pointing at nothing. Fix the stage with mkdir -p /var/lib/rpm && rpm --initdb or copy the rpmdb from the builder stage.
Is rpm --rebuilddb destructive, and can non-root users run it?
It reads existing headers and rewrites the database — non-destructive, but root-only for the system db; still run cp -a /var/lib/rpm /var/lib/rpm.bak-$(date +%F) first because --rebuilddb cannot salvage truncated header files. Non-root users target their own db with mkdir -p ~/.rpmdb && rpm --dbpath ~/.rpmdb --initdb.