Debian/Ubuntu:
Use aptitude on Debian and then Ctrl-T in the menu to perform clean up of aptitude cache.
apt-get commands:
To reclaim the space, use the following commands:
sudo apt-get autoclean
This command remove from the cache packages .deb that have an older release than the programs you have installed.
sudo apt-get clean
Remove all the packages from the cache. The only drawback might be is if you want to reinstall a package, you have to download it again.
sudo apt-get autoremove
This command deletes orphaned packages, or dependencies that are installed after you install an application and then remove it, so they are no longer needed.
dpkg is sometimes required, show you a list of packets you can purge:
sudo dpkg --get-selections | grep deinstall
More details from Linuxaria article:
http://linuxaria.com/howto/how-to-free-some-space-with-apt-get?lang=en
CentOS/RedHat/Fedora:
If you’ve been messing about with downloading and installing third party repositories, and have subsequently deleted your explorations, what you may not know is that your old files may still be junking up your repository cache. To clear the thing out, and speed up your server, commit the following lines to terminal:
sudo yum clean packages
sudo yum clean headers
These commands will purge your yum system by removing old packages. The header command cleans the repositories as well. If you want to run both commands as in packages and headers, then use:
sudo yum clean all