How can I configure apt-get to clean automatically after every install

You just need to add it at the apt configurations files. Just run:

sudo sh -c "echo 'DSELECT::Clean "always";' >> /etc/apt/apt.conf.d/99AutomaticClean"

This will trigger automatic clean each time you do upgrade.

Lets explain this entry, from the man page:

Clean

Cache Clean mode; this value may be one of always, prompt, auto, pre-auto and never. always and prompt will remove all packages from the cache after upgrading, prompt (the default) does so conditionally. auto removes only those packages which are no longer downloadable (replaced with a new version for instance). pre-auto performs this action before downloading new packages.

More info:

https://groups.google.com/d/msg/linux.debian.user/aK2jvfL_tuw/rUd6i6bd4YQJ


Write a shell script!

sudo nano /usr/bin/aptinstaller 

Inside this file type:

#!/bin/bash
sudo apt-get install $1
sudo apt-get -y autoclean
sudo apt-get -y autoremove  

Save and exit from nano and type:

sudo chmod +x /usr/bin/aptinstaller 

Now everytime you would type

sudo aptinstaller <package-name> 

It would install and then clean.

Tags:

Apt