Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

On an embedded system with a very limited disk space I have the folder /var/cache/apt full with some 700MB of srcpkgcache.bin.* and a couple of large *.bin files.

Performing sudo apt-get clean did not make a visible difference.

Is it safe to manually delete these *.bin* files?

share|improve this question

marked as duplicate by bain, Eric Carvalho, Fabby, Charles Green, Andrea Corbellini Feb 2 '15 at 16:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

As of Ubuntu 14.04 it is perfectly safe to remove the *.bin files in said folder - assuming no apt-related process is currently running. The next apt-get update will regenerate the *.bin files. This question is decidedly not about the files in /var/cache/apt/archives, but the files /var/cache/apt/*.bin. Big difference. The former can be cleaned by issuing apt-get clean, the latter has to be manually removed. Clearly those voting to close the question have not read the question properly. Unfortunately I cannot vote to reopen after awarding some of my rep in bounties. – 0xC0000022L Jun 1 '15 at 15:50

Not really. Those files help your system determine what is available and what isn't. Emptying that directory will result in a broken apt-get system. Here are a couple of tips.

First, auto clean

add a

DPkg::Post-Invoke { "apt-get clean"; };

to the end of /etc/apt/apt.conf. It will make apt and dpkg processes take longer, but will make it so your cache directory is always clean.

Next, Remove archives

Start by removing and disabling all source archives (that your not using). On an embedded system you likely don't need them. Next remove all the archives that are not in use. You can run apt-cache policy to figure out what repo a package is coming from if your not sure.

More Removal of archives

Some PPAs are horrid about having huge number of packages in them when you only need 1 or 2. Try disabling those PPAs and just installing the deb files manually. You save space in those cases, but you loose auto update. Keep in mind that dpkg will handle dependencies, so you can still install thing-with-tons-of-deps.deb then run apt-get -f install to fetch the dependencies.

Totally Extreme Answer 1

Because were talking about an embedded system, 90% of the main repos won't do you any good. To handel this you could run your own apt-get repo server See this link. It's not easy, and it's a PIA for just one machine. But if you have several of these machines it's totally worth it. (You apt repo server can host just a subset of packages that you actually use. You don't need to mirror the whole thing)

Totally Extreme Answer 2

If space is really that large of an issue, then you can disable apt all together and revert to manually installing via dpkg. I have had to do this on several embedded systems. It works, but it's an admin nightmare.

share|improve this answer
This is a great answer (especially the totally extreme ones) but /etc/apt/apt.conf no longer exists in Ubuntu 14.04. What is the current best practice? – zachaysan May 22 '15 at 16:01
JUst make the file if it doesn't exist. It will still be read. – coteyr May 25 '15 at 14:22
Please, why do you write it is not safe to remove the *.bin files? Any run of apt-get update will regenerate those files from scratch (tested). For example my use case is that I want to create LXC container templates and want to strip the archive down as much as possible. I cannot see any reason ho it's unsafe. And your answer doesn't indicate a reason, just states that it is unsafe. Tested that it's perfectly safe on Ubuntu 14.04. – 0xC0000022L Jun 1 '15 at 15:48

Keep the pkgcache.bin and srcpkgcache.bin, you can safely delete the others. Don't touch the directories!

share|improve this answer
OK, thanks. I temporarily moved the *bin.* files to a backup folder. However, why does apt-get manages the cache inside the cache? A cache directory should be a temporary storage by nature. – ysap Nov 28 '12 at 16:22
This issue is bugreported already. :) See here – Frantique Nov 28 '12 at 16:23

You can of course create a NFS-share (network filesystem) for this. Leave these files on a server and mount the share only when you want to update/install packages. In embedded environments, the installation will usually be relatively static anyway.

sshfs is another good option, is much easier to set up (basically only requires SSH which is standard), but it has more overhead (slower).

share|improve this answer
This should technically work, except you don't have full control of when apt runs. If you use something like this you need to make sure that you disable the "automated" tasks like cron jobs that run apt-get update. – coteyr Nov 29 '12 at 15:22

I used

sudo apt-get autoclean

And I can recover my space a lot !

HTH Tawatchai S.

share|improve this answer
This answer did not actually address the question. The questioner has stated that they have started trying to use the apt-get clean process, but not removed as much from their directory as they feel is needed. – Charles Green Jun 27 '14 at 4:10

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