Tombuntu

Free Disk Space from APT's Cache

Ubuntu doesn’t require a lot of disk space to install, but if you’ve installed in a virtual machine with a small virtual drive, or partitioned most of your disk for your /home, you may need to free up some space on a system occasionally.

The APT package management system keeps a cache of DEB packages in /var/cache/apt/archives. Over time this cache can grow quite large and hold a lot of packages you don’t need.

For example, I installed AWN from a repository that frequently updates to the latest development versions. As a result, /var/cache/apt/archives contained 11 different versions of the package avant-window-navigator-trunk.

It’s easy to clear APT’s cache using apt-get. The autoclean command removes packages that are definitely useless (packages that are outdated):

sudo apt-get autoclean

Running autoclean reduced the cache’s size from 378.7 MB to 293.3 MB on my main system. (85.4 MB freed.)

The clean command clears the cache entirely:

sudo apt-get clean

Running clean emptied the cache of all 378.7 MB of packages.

Clearing APT’s cache completely shouldn’t have any adverse effects other than if you reinstall a package, it will first need to be redownloaded.

[update] Commenter EarloftheWest has pointed out that Synaptic includes options for deleting downloaded packages and a button to clear the cache. These can be found in Synaptic under Settings->Preferences->Files.

Archived Comments

mkwerner

Nice tip Tom! I was wondering if Apt could do something like that, but never took the time to look.

Regards,
M.

Alok

Thank you for this tip . Issuing autoclean reduced the size of my cache from 854 MB to 690 MB. But i would not recommend clean for people with slow internet connection unless you are drastically short of disk space.

elbeto

Don’t forget to mention the great command:

sudo-apt-get autoremove, who deletes all the orphan packages or dependencies that were left after removing an application.
I always use both of the commands together

elbeto

EarloftheWest

You can also change you preferences in synaptic to delete files after they have been installed and you can clean your cache from there.

vinicius

if you are likely to reinstall ubuntu, it’s good to first backup useful packages in apt cache with aptoncd to avoid downloading tons of updates after installation

Mouth

“sudo apt-get install localepurge”
… also gives you a huge saving in disk space. It removes locale files for unused languages, from packages installed.

Jesse

Where can I find that AWN repository? I’ve been repeatedly recompiling from source.

Tom

Jesse:
You can find the AWN repo here:
https://launchpad.net/~awn-testing/+archive

budiyanto

Hi,
just want to share a bit, if you have more than 1 machine, you can use these files to update the other machines. Just take a note of all the updates, then copy them to the /var/cache/apt/archives of the target machines, when ready, click update, it’ll automatically install them with no need to download the same files all over again. If it breaks, check if you have copied the correct files, if unsure, delete them then run sudo apt-get install -f from terminal. This really helps if you have low speed connection and save bandwidth.

dave

check this nice guide how to cleanup ubuntu system to create more space http://www.ubuntugeek.com/cleaning-up-all-unnecessary-junk-files-in-ubuntu.html

jonny rocket

dude, you da shiznit!

Respond via email