RPM packages in CentOS are stored in the /var/cache/dnf directory (for DNF, the default package manager since CentOS 8) or /var/cache/yum (for YUM in CentOS 7 and earlier). These are temporary download caches; the actual installed files from an RPM are extracted to their final locations across the filesystem, typically under /usr, /etc, and /var.
Understanding RPM and Package Managers
RPM (RPM Package Manager) is the low-level package format used by CentOS, RHEL, Fedora, and other Red Hat–derived distributions. An RPM file (with a .rpm extension) is an archive containing the program’s files, metadata (name, version, dependencies), and scripts for pre- and post-installation tasks. The high-level tools yum and dnf handle dependency resolution, repository metadata, and downloading RPMs before handing them to rpm for installation.
When you run sudo dnf install httpd, DNF downloads the httpd RPM (and its dependencies) into its cache, then calls rpm -i to install the packages. The cache is a working directory, not a permanent storage location—after installation, the RPM files may be kept or deleted depending on your cache settings.
Default Cache Locations by CentOS Version
- CentOS 8 and later (DNF):
/var/cache/dnf - CentOS 7 and earlier (YUM):
/var/cache/yum
Within these directories, you’ll find subdirectories named after each enabled repository (e.g., /var/cache/dnf/baseos-.../packages/). The actual .rpm files are stored in the packages/ subdirectory of each repository folder. For example, a downloaded httpd RPM on CentOS 8 might be at /var/cache/dnf/baseos-xxxxxxxx/packages/httpd-2.4.37-62.module_el8.5.0+323+...x86_64.rpm.
If you manually download an RPM with wget or curl from a website, it goes wherever you specify—there is no default location. The cache paths above are only for packages fetched by the package manager.
How to Find Downloaded RPMs
To see what RPMs are currently in the cache, use find or ls:
sudo find /var/cache/dnf -name "*.rpm"
On CentOS 7, replace dnf with yum.
If the cache is empty, it may have been cleaned automatically or manually. You can force DNF to keep downloaded packages by setting keepcache=1 in /etc/dnf/dnf.conf (or /etc/yum.conf on CentOS 7). After changing this, future downloads will remain in the cache even after installation.
Cleaning the Cache
Over time, cached RPMs can consume significant disk space. To free space, run:
sudo dnf clean all(CentOS 8+)sudo yum clean all(CentOS 7)
This removes all cached packages and metadata. It does not affect installed programs—only the downloaded .rpm files are deleted. Running this command is safe and often recommended after major updates.
Where Installed RPM Files Actually Go
The cache is only a staging area. When an RPM is installed, its files are placed according to the package’s file list. Common destinations include:
/usr/bin– executable programs/usr/liband/usr/lib64– libraries/etc– configuration files/var– variable data like logs and databases/usr/share– documentation and architecture-independent files
To see exactly where a package’s files went, use rpm -ql <package-name>. For example, rpm -ql httpd lists every file that the httpd package installed.
Common Misconceptions
A frequent misunderstanding is that RPM packages are “stored” in the same place as the installed program. In reality, the .rpm file is a compressed archive; once installed, the archive itself is no longer needed. The installed files are extracted and scattered across the filesystem. If you delete the cache, the program keeps working normally.
Another misconception is that /var/cache/yum or /var/cache/dnf contains all RPMs ever downloaded. In fact, DNF and YUM automatically remove cached packages after installation unless keepcache is enabled. So the cache is usually empty or contains only recently downloaded packages.
Frequently Asked Questions
Can I change where DNF stores downloaded RPMs?
Yes. In /etc/dnf/dnf.conf, you can add cachedir=/path/to/dir to change the base cache directory. For YUM on CentOS 7, edit /etc/yum.conf and set cachedir=/path/to/dir. The directory must exist and be writable by the package manager.
Is it safe to delete /var/cache/dnf?
Yes. The cache contains only downloaded packages and metadata. Deleting it will not affect installed software. The next time you run dnf, it will simply re-download any needed metadata. However, do not delete the directory itself—use dnf clean all to remove its contents properly.
Why is my cache empty after installing a package?
By default, DNF and YUM delete the downloaded RPM files after successful installation. If you want to keep them, set keepcache=1 in the configuration file. This is useful if you want to reinstall without re-downloading or if you need to copy the RPM to another machine.
How do I install an RPM file I downloaded manually?
Use sudo dnf install /path/to/file.rpm (or sudo yum localinstall /path/to/file.rpm on CentOS 7). This will resolve dependencies from enabled repositories. Alternatively, sudo rpm -ivh /path/to/file.rpm installs it directly, but you must manually resolve any missing dependencies.
What is the difference between /var/cache/dnf and /var/cache/yum?
They are the same concept, just for different package managers. CentOS 8 switched from YUM to DNF as the default, so the cache directory changed. If you have both directories (e.g., after upgrading), the old YUM cache may contain leftover packages from before the upgrade, but it is no longer used.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Arctic Sea Ice Forecasts Disagree: What to Do
- MySQL Workbench to VPS: SSH Tunnel Setup
- Bluesky Beginners Guide: How to Get Started5.00 min/km
- LG V20 Won’t Turn On? Fixed
- Snagit vs Camtasia: Which One Do You Need?
- Scale a Small Business Without Losing Culture