I spent a couple of sleepless nights to switch from Gentoo Linux to Fedora Core, since I became a Red Hat employee. Although Fedora Core is really a nice Linux distribution, I still miss the concept of ‘world’ in Gentoo.
When a user installs a Gentoo package, the name of the installed package is appended the ‘world’ file. What’s interesting is that the dependencies of the installed package are not added to the ‘world’ file. What happens when you uninstall the package registered in the world file is that the name of the package is removed. It’s very simple, but it’s powerful when you don’t want unnecessary packages take up disk space. (Yeah, I am a paranoid. 🙂
Now, from the world file, we know what packages were installed by our own request and what were installed just as dependencies, so Gentoo can identify the unnecessary packages that is safe to be removed. Consequently, running ‘emerge --depclean‘ cleans up all the unnecessary packages.
Can’t we do this in Fedora Core or any RPM-based Linux distribution? The answer is yes.
First off, you have to install ‘rpmorphan‘. rpmorphan has the ‘keep’ file which does the same role with the ‘world’ file. It’s located at /var/lib/rpmorphan/keep, which should be empty initially.
Let’s try to find what packages are unnecessary:
$ rpmorphan -all
Unfortunately, you will see so many essential packages that you want to keep. It’s just because you didn’t add them to the ‘keep’ file yet. For example, you can add ‘gnome-terminal’ to the keep file like the following:
$ rpmorphan -add-keep gnome-terminal
Once you finished adding all the packages that you want to keep to the keep file, now you are ready to run the following shell script file (rpmdepclean).
#!/bin/sh # rpmdepclean while true; do ORPHANS1="`rpmorphan --all | xargs echo`" if [ -n "$ORPHANS1" ]; then echo -n "$ORPHANS1 " yum -q -y remove $ORPHANS1 > /dev/null 2>&1 || exit 1 fi ORPHANS2="`rpmorphan --guess-all | xargs echo`" if [ -n "$ORPHANS2" ]; then echo -n "$ORPHANS2 " yum -q -y remove $ORPHANS2 > /dev/null 2>&1 || exit 1 fi if [ -z "$ORPHANS1" ] && [ -z "$ORPHANS2" ]; then echo exit 0 fi done
Please double-check you added required packages to the keep file. Otherwise, things can go screwed up. You have been warned. If you are in doubt, you can always run yum remove manually, which is safer.