22

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?

  • 6
    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
  • 3
    This is not a duplicate. The linked answer is about the subdirectory archives within /var/cache/apt/, this one is about the *.bin* files. – Olaf Dietsche Sep 3 '16 at 10:25
  • 1
    Possible duplicate of Remove files from /var/cache/apt (NOT archives) – Eliah Kagan Oct 21 '17 at 23:50
11

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.

| 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
  • 1
    JUst make the file if it doesn't exist. It will still be read. – coteyr May 25 '15 at 14:22
  • 5
    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
  • 1
    You're saying including apt-cache clean in a dpkg call will result in cleaner cache, but user says apt-cache clean didn't clean anything for them. Also your answer is totally wrong because dpkg doesn't use /var/cache/apt/* content to get informed for package statistic. – Anwar Apr 18 '17 at 14:09
  • 1
    The apt-get manpage clearly describes the function of clean as * clean clears out the local repository of retrieved package files. It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.* If it is dangerous, there would be no such function to clean. – Anwar Apr 18 '17 at 14:15
3

You can of course delete pkgcache.bin and srcpkgcache.bin, nothing happens. Just run apt-get update to re-create them.

| improve this answer | |
  • ... and is this true independently of the deletion of the .deb files? – einpoklum Jan 2 '18 at 23:07
  • sub optimal as this removes all the repo signing keys resulting in breakage – krad Feb 19 at 13:00
1

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

| 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 delete pkgcache.bin and srcpkgcache.bin, nothing happens. apt-get update recreates them. – Tomas M Oct 16 '17 at 8:26
0

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).

| 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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