June 15, 2015

Debian and Arch Linux package cleanup – aptorphan/pacorphan

Filed under: Technical — Tags: , , , , — James Bunton @ 12:00 am

Once upon a time there was a tool called deborphan. It finds orphaned packages which could be removed from the system. You can maintain a list of ‘keepers’ to stop it suggesting removal of things that you want.

I wanted to extend this to work with the builtin “auto-installed” flag that aptitude stores for all packages. I also wanted it to work with Arch Linux.

The goals

  • Keep a list of explicitly installed packages in regular files (~/.{apt,pac}orphan/).
  • Ability to share these lists between systems. I use git repos for this.
  • Ensure there are no missing packages or unwanted packages on the system.
  • All non-explicitly installed packages in the system should be marked as auto-installed in the package manager.

How to use it

  1. Download aptorphan for Debian/Ubuntu or pacorphan for Arch Linux.
  2. Create a directory: ~/.aptorphan/ or ~/.pacorphan/
  3. Populate these directories with packages that you wish to keep. You can have multiple files, and you can use comments and blank lines.
  4. Run the tool, it will give you a list of suggested commands to clean up your system.
  5. Read these commands and decide if they make sense before running them.
  6. Repeat from (4) until there’s nothing left to do.

Example – Newly installed package

$ sudo aptitude install python-genshi


$ aptorphan
# Found explicitly installed packages to keep or remove
echo python-genshi | tr ' ' '\n' >> ~/.aptorphan/keep
sudo aptitude --schedule-only install python-genshi+M

The package python-genshi is installed, but not listed in ~/.aptorphan/. There are two suggested solutions. You can add the package to your keepers list, or you can remove it. Note that for safety aptorphan does not remove packages immediately, you must run aptitude install for your changes to be applied.

Example – Copying package list from another computer

$ scp somehost:.aptorphan/* ~/.aptorphan/


$ aptorphan 
# Found packages which should be installed
sudo aptitude --schedule-only install pidgin