I need to make sure that the apt package cache (I mounted it in RAM, so it’s important not to clutter up the RAM) is automatically cleared after a successful installation/update process. Is it possible?
If /var/cache/apt/archives is mounted in RAM, you can let APT auto clean it after each successful install or upgrade. Create a small config file:
sudo mkdir -p /etc/apt/apt.conf.d
echo 'APT::Clean-Installed "true";' | sudo tee /etc/apt/apt.conf.d/99clean
From now on, apt will clean out downloaded packages it no longer needs after installs/updates, so your RAM-backed cache will not keep growing.
also since it’s in tmpfs, anything left there also disappears on reboot so you don’t need extra cron jobs or scripts.
Many tanks! It worked!
Issue was in cache size. It was cluttering RAM and I had to reboot it to clean up. This fixed issue
As I understand, this will clean ONLY cache, right?
If you have limited RAM, you should be runing ZRAM:
While this is certainly a solid and automatic solution, I have a manual solution that truly is not MUCH more difficult, except for the fact that a person has to take care of it. For a guy like me, I’d rather have complete control, so as I acknowledge, this is one good method, an alternative is to create a few really convenient alias commands in your .bashrc (assuming you’re using Bash), otherwise equivalent alias commands in whatever you do use.
Example:
alias aa=‘sudo apt autoremove’
alias ac=‘sudo apt clean’
Love this. I love time savers also. But like @Brian_Masinick I prefer the control/timing.
My alias of choice is: upd for:
sudo apt update && sudo apt dist-upgrade && sudo apt autoremove && sudo apt autoclean
By default, apt stores to disk not ram. But you can clean ram manually also using:
sync; echo 3 > /proc/sys/vm/drop_caches
This immediately frees up RAM (note: this will increase disk I/O and slow down applications that need to reload data into cache afterward).
It’s an option, but with 16 GB of RAM, you really should not have too much space issues.