Tech Tip: Removing Unnecessary Packages on Debian Systems

 in

The command deborphan can be used to check for unnecessary (orphaned) packages. By default deborphan searches for orphaned libraries, but you can have it search for other types of packages also: data packages, dev packages, etc. by specifying one of its many --guess-* command line options.

If you don't have deborphan installed you can install it via:

$ sudo apt-get install deborphan

Now, to remove all orphaned (library) packages simply run:

$ sudo deborphan | xargs apt-get -y remove purge

To remove all orphaned data packages run:

$ sudo deborphan --guess-dev | xargs apt-get -y remove purge

To see all the orphaned packages on your system run:

$ deborphan --guess-all

The following excerpt comes from the deborphan man page and relates to the --guess-* options:

deborphan can try to guess what packages may not be of much use to you by examining the package's name. It will pretend the package is in the main/libs section, and report it as if it were a library. This method is in no way perfect or even reliable, so beware when using this!

So it's usually a good idea to view the output of deborphan and make sure that it appears reasonable before feeding it to apt-get -y remove purge.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

A less extreme aproach

Ted Kotz's picture

I usually like to pipe it too markauto rather than immediately using purge so that aptitude gets a vote in the removal process.

test first:
deborphan --guess-all | xargs aptitude -ys markauto

then do it:
deborphan --guess-all | xargs aptitude -y markauto

then I remove all lingering configs with
test first:
aptitude search ~c

then do it:
aptitude purge ~c

Sorry, I ment

Anonymous's picture

Sorry, I ment autoremove.

When i remove or purge something that was installed with "suggested" or with a lot of dependencys and something was left, the "autoremove" removes them.
For example I installed "extremetuxracer", "removed" it and used autoremove after:

sudo apt-get autoremove
Reading package lists ... Done
Building dependency tree
Reading state information ... Done
The following packages will be REMOVED:
extremetuxracer-date
libmikmod2
libsdl-mixer1.2
libsmpeg0
tcl8.5
0 upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
After this operation there will be released 37.4 MB of disk space.
Continue [Y / n] ? Y
(Reading database ... 62,198 files and directories currently installed.)
Removing extremetuxracer-date ...
Removing libsdl-mixer1.2 ...
Removing libmikmod2 ...
Removing libsmpeg0 ...
Removing tcl8.5 ...
Processing triggers for man-db ...
Processing triggers for menu ...

My man for apt-get:

APT-GET(8)

NAME
apt-get - APT package handling utility -- command-line interface

SYNOPSIS
apt-get [-sqdyfmubV] [-o= config_string ] [-c= config_file ] [-t= { target_release_name | target_
release_number_expression }] {update | upgrade | dselect-upgrade | dist-upgrade | install pkg [ { =pkg_version_number | /target_release_name } ] ... | remove pkg... | purge pkg... | source pkg [ =pkg_version_number ] ... | build-dep pkg... | check | clean | autoclean | autoremove | {-v | --version} | {-h | --help}}

autoclean

Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless. This allows a cache to be maintained over a long period without it growing out of control. The configuration option APT::Clean-Installed will prevent installed packages from being erased if it is set to off.

autoremove

autoremove is used to remove packages that were automatically installed to satisfy dependencies for some package and that are no more needed.

apt v:0.7.20.2+lenny1

Similar

Mitch Frazier's picture

Guess I was looking at an old man page, I didn't see the autoremove option (I use openSUSE so I'm not a regular apt-get user). I found a newer man page and yes it is there.

So, yes, autoremove is similar to deborphan but from what I read they don't always produce the same results (in terms of what they think can be removed).

Mitch Frazier is an Associate Editor for Linux Journal.

And what about apt-get

Anonymous's picture

And what about apt-get auroremove ? Or apt-get autoclean ?

Different Thing Completely

Mitch Frazier's picture

That's something completely different, from the man page:

clean
clean clears out the local repository of retrieved package files. It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/. When APT is used as a dselect(8) method, clean is run automatically. Those who do not use dselect will likely want to run apt-get clean from time to time to free up disk space.
autoclean
Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless. This allows a cache to be maintained over a long period without it growing out of control. The configuration option APT::Clean-Installed will prevent installed packages from being erased if it is set to off.

I don't see an "autoremove" option, or "auroremove" for that matter.

Mitch Frazier is an Associate Editor for Linux Journal.

See above

Mitch Frazier's picture

I was looking at an old man page, autoremove does exist, see the comment above.

I use openSUSE so I don't use apt-get very often.

Mitch Frazier is an Associate Editor for Linux Journal.

Status file is in an improper state

A W's picture

deborphan installed fine, but when I ran 'deborphan --guess-all' I got the error message below:

deborphan: The status file is in an improper state.
One or more packages are marked as half-installed, half-configured,
unpacked, triggers-awaited or triggers-pending. Exiting.

Any suggestions?

Check These

Mitch Frazier's picture

Check these two boogs:

Boog 1

Boog 2

(found at sidux).

Mitch Frazier is an Associate Editor for Linux Journal.

Thanks! I ran the command

AW's picture

Thanks! I ran the command below and it showed me which packages had an error.

egrep '^Status: |^Package: ' /var/lib/dpkg/status | egrep -B 1 'half-installed|half-configured|unpacked|triggers-awaited|triggers-pending'

deborphan works now.

doesn't aptitude do this?

augmentedfourth's picture

How is this different from 'sudo aptitude purge ~c'?

Aptitude ~c

Mitch Frazier's picture

According to the aptitude manual:

~c   Matches packages which have been removed, but whose configuration files remain on the system (ie, they were removed but not purged).

On the other hand, deborphan attempts to find packages which are installed but which are no longer needed, at least not needed by any of the other installed packages.

Mitch Frazier is an Associate Editor for Linux Journal.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix