I am in the process of cleaning up my system. And I see a lot of space occupied by this folder /var/cache/apt/archives
(1.5GB). Is it absolutely necessary to keep all these archives?
-
I have an entry in crontab that runs a script once a month. echo yourpassword | sudo -S apt-get clean. This is reasonable safe if you are the only one with physical access to your computer.– fixit7Nov 20, 2022 at 11:22
5 Answers
You don't need to keep them around if you don't want them. Executing a
sudo apt-get clean
will clean out the directory.
-
Why after I have issued this command I still can see the cached deb files in the Ubuntu Tweek tool? Jul 22, 2016 at 16:59
-
@Cristiano it might be that the tool is in a partially-installed state and so apt thinks it needs to keep it.– Doktor JAug 6, 2019 at 16:14
Seems like
sudo apt-get autoclean
is a better choice than
sudo apt-get clean
autoclean
will only remove "useless" archives
From the man page:
Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless. This allows a cache to be maintained over a long period without it growing out of control. The configuration option APT::Clean-Installed will prevent installed packages from being erased if it is set to off.
-
11Even if this is what I also remembered from way back - turns out, for me (on 11.04)
autoclean
did NOT remove files in/var/cache/apt/archives/
- whileclean
did...– sdaauMar 4, 2014 at 20:18 -
I'm actually seeing the opposite,
autoclean
basically emptied the directory whileclean
did nothing. Dec 24, 2014 at 18:32 -
-
1No, clean is the better choice if you want to save disk space. My testing (ubuntu 18) showed clean removed 18G when autoclean removed little (less than 1 GB, if that)– gerardwJul 14, 2019 at 16:15
-
1useless archives to me are installed ones (I download only most times), by not specifying what "useless" actually means makes that option useless (pun intended :)) Dec 16, 2020 at 20:42
You can adjust settings in Synaptic package manager, menu Settings/Preferences, the Files tab. From there you can also delete the cache.
-
"delete downloaded packages after installation" is what I needed, thx! Dec 16, 2020 at 20:30
-
"delete downloaded packages after installation" is what I needed, thx! a pity the clean button ignores our option see askubuntu.com/questions/1300676/… Dec 16, 2020 at 20:44
It is better to save packages elsewhere then clean it up [Jorge Castro's process]. When you reinstall OS or a package it will not download again which save time and bandwidth. apt-get first check require packages in local storage[/var/cache/apt/archives] if does not exists then download else just do install. So you can save packages for future uses.
-
5I doubt he will need all the 1,5Gb of updates to use on a new system! Oct 12, 2011 at 20:13
-
1They can be moved on a CD or other support, so they don't waste space on the local drive. This is called a 'local repository'.– ignisNov 7, 2012 at 20:37
-
1Save packages elsewhere? Yes, that's what I've done here. I've
mv
'd the whole/var/cache/apt/archives
to/usr/tmp/apt-archive-cache
and set anarchives
symbolic link in/var/cache/apt
accordingly. Since especiallyaudacity
likes to store temporary files in/var
, this directory should always be taken care of so that it never runs out of space. Oct 2, 2014 at 13:09
If you have automatic unattended upgrades, like a Google Cloud VM has, you can today read the information in this file:
/usr/lib/apt/apt.systemd.daily
Then add and adjust a new file here:
/etc/apt/apt.conf.d/10periodic
The most relevant settings, I think, are these:
# APT::Archives::MaxAge "0"; (old, deprecated)
# APT::Periodic::MaxAge "0"; (new)
# - Set maximum allowed age of a cache package file. If a cache.
# package file is older it is deleted (0=disable)
and maybe even more so these two:
# APT::Periodic::AutocleanInterval "0";
# - Do "apt-get autoclean" every n-days (0=disable)
#
# APT::Periodic::CleanInterval "0";
# - Do "apt-get clean" every n-days (0=disable)
I had to add the bottom two, because my VM was running out of space and the apt cache was several GBs of old junk.
I added them like this.
APT::Periodic::AutocleanInterval "7";
// Do "apt-get autoclean" every n-days (0=disable)
APT::Periodic::CleanInterval "7";
// Do "apt-get clean" every n-days (0=disable)
And maybe even only the last setting is necessary, as it cleans more than auto-clean does.
APT::Periodic::CleanInterval "7";
// Do "apt-get clean" every n-days (0=disable)