I would like to cleanup my local repository after each upgrade. When I add newer version of packages to pool and regenerate indexes with dpkg-scanpackages, program warns about old versions of packages (in case -m option is not passed):

dpkg-scanpackages: warning: Package php5-common (filename pool/local/php5-common_5.3.6-13ubuntu3.3_amd64.deb) is repeat but newer version;
dpkg-scanpackages: warning: used that one and ignored data from pool/local/php5-common_5.3.6-13ubuntu3.2_amd64.deb!

I'm looking for an automated way to safely remove old packages from disk. I'll call such a script safe if it do not delete an old package if a newer version is available and removing old version will cause an unmet dependency in local repository


Have you tried apt-get clean and apt-get autoclean?

apt-get clean removes everything except lock files from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/. Thus, if you need to reinstall a package APT should retrieve it again.

apt-get autoclean removes only package files that can no longer be downloaded.

| improve this answer | |
  • How can I use autoclean for my repository? – sorush-r Mar 8 '12 at 5:46
  • Running the command doesn't work? Have you tried bleachbit ? apt-get install bleachbit. This is a cleanup utility that erases various caches, delete cookies, clears internet history, removes unused localisations, shreds logs, and deletes temporary files. It doesn't remove anything you can't live without, so it's safe to use and all it does is clear out logs and caches. [link] (bleachbit.sourceforge.net) 'BleachBit - cleanup tool for Ubuntu' – LnxSlck Mar 12 '12 at 14:11
  • I need to delete old packages from a local repository, say in /home/soroush/repo – sorush-r Mar 12 '12 at 18:03

For removing the obsolete packages, try

sudo apt-get autoremove
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.