Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there any way do apt-get clean after apt-get install automatically, like in other distros?

share|improve this question
Thanks to @Braiam I found a bug in Ubuntu and I'll report it. In Debian Braiam's solution work fine. –  Tiago Carrondo Dec 12 '13 at 13:23
related: How do I free up disk space? –  rubo77 Sep 12 at 1:23

3 Answers 3

up vote 10 down vote accepted

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:


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:


share|improve this answer
I guess it should need a semicolon at the end ;! and therefore it should be sudo sh -c "echo 'APT::Get::Clean=always;' >> /etc/apt/apt.conf.d/99AutomaticClean" –  Indian Dec 12 '13 at 12:34
@Braiam I've tried it and it doesn't work. I even tried APT::Get::Clean "always" like in other files but no luck. any clue? –  Tiago Carrondo Dec 12 '13 at 13:01
@Braiam no luck –  Tiago Carrondo Dec 12 '13 at 13:06
@TiagoCarrondo how about now? This usenet message says that is the winner. –  Braiam Dec 12 '13 at 13:11
I've tried that already after your first post. Going to change file location... wait –  Tiago Carrondo Dec 12 '13 at 13:15

Write a shell script!

sudo nano /usr/bin/aptinstaller 

Inside this file type:

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.

share|improve this answer
I prefer an option, but sound like a preety good plan B, thx –  Tiago Carrondo Dec 12 '13 at 13:03

How about appending ?

sudo apt-get install pkg_name ; sudo apt-get autoclean

two sudos are needed for above case , because if sudo time expires then normal command dont work.

share|improve this answer
or better yet sudo sh -c "apt-get update; sudo apt-get upgrade" so the sudo won't expires ;) –  Braiam Dec 12 '13 at 13:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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