Cleaning up deinstalled packages on Debian (and Ubuntu)
Disclaimer: this is for advanced users, use at your own risk.
If you run Debian on the same system for a while, packages get removed automatically and they never get purged. This means that config files and other useless cruft gets left over after many upgrades. I searched the web for an easy one-liner but didn't find one, so I hope this helps someone![]()
See how many packages are in the 'deinstalled' state with this command:
To purge all of these packages at once:
Code:
<pre class='alt2' dir="ltr" style='
margin: 0px;
padding: 6px;
border: 1px inset;
width: 640px;
height: 34px;
text-align: left;
overflow: auto'>dpkg --get-selections | grep deinstall | wc -l</pre>
I ran this on all of my systems and they've got a bit more free space now
Code:
<pre class='alt2' dir="ltr" style='
margin: 0px;
padding: 6px;
border: 1px inset;
width: 640px;
height: 34px;
text-align: left;
overflow: auto'>dpkg --get-selections | grep deinstall | sed 's/deinstall/\lpurge/' | dpkg --set-selections; dpkg -Pa</pre>
Edit: For Ubuntu and others that use sudo:
And when you do apt-get autoremove you will still have stuff left over unless you do:
Code:
<pre class='alt2' dir="ltr" style='
margin: 0px;
padding: 6px;
border: 1px inset;
width: 640px;
height: 34px;
text-align: left;
overflow: auto'>dpkg --get-selections | grep deinstall | sed 's/deinstall/\lpurge/' | sudo dpkg --set-selections; sudo dpkg -Pa</pre>
<pre class='alt2' dir="ltr" style='
margin: 0px;
padding: 6px;
border: 1px inset;
width: 640px;
height: 34px;
text-align: left;
overflow: auto'>aptitude --purge-unused purge packagename</pre>
Code:
<pre class='alt2' dir="ltr" style='
margin: 0px;
padding: 6px;
border: 1px inset;
width: 640px;
height: 34px;
text-align: left;
overflow: auto'>apt-get --purge autoremove</pre>
-
ALLurGroceries Vegan Vermin Super Moderator
-
thanks...
i've been using deborphan, but will try this too
Code:sudo deborphan | xargs sudo apt-get -y remove --purge
-
Thanks, that's good to know. I've been doing sudo apt-get autoremove or whatever it is, but it would be nice to actually purge the stuff.
-
THANKS what would I do without your advice!
-
Nice, handy, thanks :.)
-
The Fire Snake Notebook Virtuoso
Do you need to do this if you purge everything you uninstall? Thats what I do, just curious. I am assuming that when you do something like aptitude purge [package name] that it purges the dependencies as well?
-
ALLurGroceries Vegan Vermin Super Moderator
If you always purge everything you shouldn't need this... but there's always the possibility that something gets automatically removed instead of purged during an upgrade.
-
ALLurGroceries Vegan Vermin Super Moderator
Oh if you want to purge dependencies u need to use:
Code:aptitude --purge-unused purge packagename
Code:apt-get --purge autoremove
-
The Fire Snake Notebook Virtuoso
Cleaning up deinstalled packages on Debian
Discussion in 'Linux Compatibility and Software' started by ALLurGroceries, Jul 16, 2009.