====== Ubuntu - Packages - Cleanup ====== APT keeps a copy of each downloaded **.deb** file in the directory **/var/cache/apt/archives/**. In case of frequent updates, this directory can quickly take a lot of disk space with several versions of each package; you should regularly sort through them. Two commands can be used: **apt-get clean** entirely empties the directory; **apt-get autoclean** only removes packages which can no longer be downloaded (because they have disappeared from the Debian mirror) and are therefore clearly useless (the configuration parameter APT::Clean-Installed can prevent the removal of .deb files that are currently installed). To save up some space via **apt-get** you can use these commands: apt-get autoclean apt-get clean **autoclean** removes unused dependencies, packages which were installed by other packages but which are no longer needed by your system. **clean** just removes all the packages in the apt cache. You can also use **autoclean** but clean frees up more space. ---- ===== Purge unused packages ===== aptitude clean --purge-unused **WARNING**: THIS OPTION CAN CAUSE DATA LOSS. DO NOT USE IT UNLESS YOU KNOW WHAT YOU ARE DOING. ---- ===== Find Package Dependencies ===== When cleaning up a system, it is recommended to consider package dependencies. To show all the packages which are installed on your system because some package recommends it, but they are not actually dependencies of packages: aptitude search '?and( ?automatic(?reverse-recommends(?installed)), ?not(?automatic(?reverse-depends(?installed))) )' can give something like this: i A apt-xapian-index - maintenance and search tools for a Xapian index of Debian packages i A exim4 - metapackage to ease Exim MTA (v4) installation i A file - Determines file type using "magic" numbers i A heirloom-mailx - feature-rich BSD mail(1) Check the output and if needed remove them all. **WARNING**: Ensure that package like libc6, sysv-rc, apt or coreutils are not removed. aptitude search '?and( ?automatic(?reverse-recommends(?installed)), ?not(?automatic(?reverse-depends(?installed))) )' | awk '{ print $3 }' | xargs dpkg -P Then we have the all time favorites to see sizes: df -h du -h | grep ^[0-9.]*M | sort -rn du -h | grep ^[0-9.]*G | sort -rn