Is it safe to manually delete the /var/cache/apt content?
Solution 1
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.
Solution 2
You can of course delete pkgcache.bin
and srcpkgcache.bin
, nothing happens. Just run apt-get update
to re-create them.
Solution 3
Keep the pkgcache.bin
and srcpkgcache.bin
, you can safely delete the others. Don't touch the directories!
Related videos on Youtube
ysap
I've been a computers/computing enthusiast since many years ago. Started coding FORTRAN on punched cards, then moved to BASIC on my MC6809 based DRAGON-64 and then the x86 IBM-PC era. I had the opportunity of working on mainframes, minis, workstations, PC's and embedded hardware. Today I am doing mainly embedded coding - C and ASM on various processors, and on various programming environments and toolchains like MS Visual Studio, Eclipse CDT, ARM DS and more. Was lucky enough to be at the right time at the right place to get to work as a VLSI designer for a top tier chip company, working on a world class processor family. Always looking to solving problem in the most elegant way! - Yaniv Sapir
Updated on September 18, 2022Comments
-
ysap over 1 year
On an embedded system with a very limited disk space I have the folder
/var/cache/apt
full with some 700MB ofsrcpkgcache.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?-
0xC0000022L almost 9 yearsAs 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 nextapt-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 issuingapt-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. -
Eliah Kagan over 6 yearsPossible duplicate of Remove files from /var/cache/apt (NOT archives)
-
-
ysap over 11 yearsOK, 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. -
m. öztürk over 11 yearsThis issue is bugreported already. :) See here
-
coteyr over 11 yearsThis 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.
-
zachaysan about 9 yearsThis 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?
-
coteyr about 9 yearsJUst make the file if it doesn't exist. It will still be read.
-
0xC0000022L almost 9 yearsPlease, why do you write it is not safe to remove the
*.bin
files? Any run ofapt-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. -
Anwar about 7 yearsYou're saying including
apt-cache clean
in a dpkg call will result in cleaner cache, but user saysapt-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 about 7 yearsThe 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. -
Tomas M over 6 yearsYou can of course delete pkgcache.bin and srcpkgcache.bin, nothing happens. apt-get update recreates them.
-
einpoklum over 6 years... and is this true independently of the deletion of the
.deb
files? -
krad over 4 yearssub optimal as this removes all the repo signing keys resulting in breakage