The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Cleaning up deinstalled packages on Debian

    Discussion in 'Linux Compatibility and Software' started by ALLurGroceries, Jul 16, 2009.

  1. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331

    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 [​IMG]




    See how many packages are in the 'deinstalled' state with this command:



    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>
    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 | sed 's/deinstall/\lpurge/' | dpkg --set-selections; dpkg -Pa</pre>

    I ran this on all of my systems and they've got a bit more free space now



    Edit: For Ubuntu and others that use sudo:


    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>

    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'>apt-get --purge autoremove</pre>
     
    Last edited by a moderator: May 8, 2015
  2. j0hn00

    j0hn00 Notebook Evangelist

    Reputations:
    70
    Messages:
    394
    Likes Received:
    0
    Trophy Points:
    30
    thanks...

    i've been using deborphan, but will try this too

    Code:
    sudo deborphan | xargs sudo apt-get -y remove --purge
     
  3. pixelot

    pixelot Notebook Acolyte

    Reputations:
    3,732
    Messages:
    6,833
    Likes Received:
    0
    Trophy Points:
    205
    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. :rolleyes:
     
  4. joeelmex

    joeelmex Notebook Evangelist

    Reputations:
    229
    Messages:
    518
    Likes Received:
    1
    Trophy Points:
    31
    THANKS what would I do without your advice!
     
  5. helikaon

    helikaon Notebook Consultant

    Reputations:
    269
    Messages:
    288
    Likes Received:
    0
    Trophy Points:
    30
    Nice, handy, thanks :.)
     
  6. The Fire Snake

    The Fire Snake Notebook Virtuoso

    Reputations:
    426
    Messages:
    2,889
    Likes Received:
    0
    Trophy Points:
    55
    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?
     
  7. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
    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.
     
  8. ALLurGroceries

    ALLurGroceries  Vegan Vermin Super Moderator

    Reputations:
    15,730
    Messages:
    7,146
    Likes Received:
    2,343
    Trophy Points:
    331
    Oh if you want to purge dependencies u need to use:
    Code:
    aptitude --purge-unused purge packagename
    And when you do apt-get autoremove you will still have stuff left over unless you do:
    Code:
    apt-get --purge autoremove
    Hope this helps. :)
     
  9. The Fire Snake

    The Fire Snake Notebook Virtuoso

    Reputations:
    426
    Messages:
    2,889
    Likes Received:
    0
    Trophy Points:
    55
    Didn't know that. Thanks.