Gentoo distfiles can grow quietly because Portage keeps source archives after packages finish building. Cleaning them frees disk space without unmerging installed packages, but an overly aggressive pass can force later rebuilds to download sources again or lose convenient downgrade archives.
Portage stores these archives in DISTDIR, which defaults to /var/cache/distfiles on current installations and can be changed in /etc/portage/make.conf. The eclean-dist command from app-portage/gentoolkit removes source archives that Portage no longer needs according to the selected protection mode.
The conservative run keeps sources for ebuilds still available in the repository. The –deep mode saves more space by protecting only distfiles tied to currently installed package versions, so use a pretend run first and avoid it when offline rebuilds, fetch-restricted source archives, or quick downgrade room matter.
Related: How to update a Gentoo world set
Related: How to remove a Gentoo package
Steps to clean Gentoo distfiles:
- Open a terminal on the Gentoo system with sudo privileges.
- Install gentoolkit if eclean-dist is not available.
$ sudo emerge --ask app-portage/gentoolkit
eclean-dist is installed by app-portage/gentoolkit. Skip this step when the command is already present.
- Print the active DISTDIR path.
$ portageq envvar DISTDIR /var/cache/distfiles
Use the printed path in the size checks below when the system uses a custom DISTDIR.
- Check how much space the distfiles directory uses before cleanup.
$ du -sh /var/cache/distfiles
- Preview the conservative cleanup.
$ sudo eclean-dist --pretend
–pretend lists files that would be removed without deleting them. If it reports that the distfiles directory is already clean, no conservative cleanup is needed.
- Remove obsolete distfiles with the conservative mode.
$ sudo eclean-dist
This deletes cached source archives that eclean-dist considers obsolete. Installed packages remain installed, but future rebuilds may need to download removed source archives again.
- Preview a deep cleanup only when more space must be recovered.
$ sudo eclean-dist --deep --pretend
–deep protects only distfiles for currently installed package versions. It can remove source archives that would have helped with downgrades or reinstalling packages that were removed earlier.
- Run the deep cleanup if the pretend list is acceptable.
$ sudo eclean-dist --deep
Skip this step on systems that need a wider local source cache for offline rebuilds, fetch-restricted packages, or rollback testing.
- Verify that eclean-dist has no further distfiles to remove.
$ sudo eclean-dist --pretend * Building file list for distfiles cleaning... * Your distfiles directory was already clean.
If eclean-dist –deep reports unavailable installed packages, remove only packages that are truly no longer needed and then rerun the cleanup. Related: How to remove a Gentoo package
- Check the distfiles directory size after cleanup.
$ du -sh /var/cache/distfiles
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.