34

For a smooth upgrade from 10.04 to 10.10, I would like to remove all packages which are not in the default repositories (e.g. chromium PPA and third-party repositories). What is the easiest way (preferably CLI) to find and remove these packages?

Edit: this question is not restricted to PPA's, I have a x2go repository as well, so I'm looking for a generic command to remove packages belonging to a certain repository. For PPA's, the question How can PPAs be removed has great answers.

Lekensteyn
  • 178,446

6 Answers6

22

Check out ppa-purge Install ppa-purge.

Usage:

ppa-purge -purge <nameofppa> [-s hostserver]

Hostserver defaults to ppa.launchpad.net.

Here is the link to the manpage for the ppa-purge command Manpage icon for reference.

19

Overcoming aptitude's Multiarch Bug for ppa-purge

Normally, as Vadim Rutkovsky and Takkat have explained, running ppa-purge with default syntax is an effective way to remove all packages provided by a PPA, properly downgrading them to versions provided in other configured software sources whenever possible.

However, as Takkat has pointed out, bug 831768 prevents ppa-purge from working properly to remove multiarch packages (like 32-bit packages installed on 64-bit systems). This is because aptitude cannot handle conflicting dependencies in multiarch packages (that's what the bug is about), and the default behavior of ppa-purge is to use aptitude to downgrade packages.

Fortunately, ppa-purge accepts the -i flag which causes it to prefer apt-get to aptitude as its backend. As documented in the bug report, using apt-get is an effective alternative to manually invoking aptitude, so running ppa-purge with the -i flag should be an effective workaround for removing/downgrading all packages provided by a PPA, including multiarch packages.

How To Do It

Here's the syntax:

sudo ppa-purge -i ppa:ppaowner/ppaname

As usual (same as when the -i flag is not used):

  • ppaowner is replaced with the owner of the PPA.
  • /ppaname is optional. If present, ppaname is replaced with the name of the PPA. If not, it defaults to ppa.

For example, suppose I had the PPA for unstable builds of qBittorrent installed, and I wanted to remove it completely, automatically downgrading qBittorrent to whatever version is available through my other software sources using apt-get behind the scenes instead of aptitude. Then I would run:

sudo ppa-purge -i ppa:hydr0g3n/qbittorrent-unstable

Where It's Documented

For some reason, a few useful options for ppa-purge are not documented in its manual page, including -i. But you can get information about them by running ppa-purge -h (or just ppa-purge with no arguments):

ek@Del:~$ ppa-purge -h
Usage: sudo ppa-purge [options] <ppa:ppaowner>[/ppaname]

ppa-purge will reset all packages from a PPA to the standard
versions released for your distribution.

Options:
    -p [ppaname]        PPA name to be disabled (default: ppa)
    -s [host]       Repository server (default: ppa.launchpad.net)
    -d [distribution]   Override the default distribution choice.
    -y          Pass -y --force-yes to apt-get or -y to aptitude
    -i          Reverse preference of apt-get upon aptitude.
    -h          Display this help text

Example usage commands:
    sudo ppa-purge xorg-edgers
    will remove https://launchpad.net/~xorg-edgers/+archive/ppa

    sudo ppa-purge -p xorg-testing sarvatt
    will remove https://launchpad.net/~sarvatt/+archive/xorg-testing

    sudo ppa-purge ppa:ubuntu-x-swat/x-updates
    will remove https://launchpad.net/~ubuntu-x-swat/+archive/x-updates

Notice: If ppa-purge fails for some reason and you wish to try again,
(For example: you left synaptic open while attempting to run it) simply
uncomment the PPA from your sources, run apt-get update and try again.

"Reverse preference of apt-get upon aptitude" is a bit cryptic. By looking at the relevant piece of the source code (ppa-purge is just a shell script, after all), we can see that this means that the default behavior is to prefer aptitude to apt-get, and the -i flag reverses this preference.

Eliah Kagan
  • 119,640
14

This script can list all packages from a particular server/branch (modifying the two declared variables):

#!/bin/bash

server="http://it.archive.ubuntu.com/ubuntu/"
branch="maverick-updates/main"

apt-cache policy $(dpkg -l | awk 'NR >= 6 { print $2 }') |
  awk -v server="$server" -v branch="$branch" \
    '/^[^ ]/      { split($1, a, ":"); pkg = a[1] }
    nextline == 1 { nextline = 0; if ($2 == server && $3 == branch) print pkg }
    /\*\*\*/      { nextline = 1 }'

if you need to list all packages not coming from a particular server, independently from the branch, replace the next-to-last line with:

nextline == 1 { nextline = 0; if ($2 != server) print pkg }
Eliah Kagan
  • 119,640
enzotib
  • 96,093
10

To at least find them, start by disabling the PPA's and run apt-get update. Then install apt-show-versions. Running apt-show-versions | grep 'No available' will then give you a list of all your installed packages that cannot be found in your configured repositories. With some command-line magic you can probably strip out the package names only and pass them to apt-get remove:

 for i in `apt-show-versions | grep 'No available' | cut -d' ' -f 1` ; do  sudo apt-get remove -y $i ; done

Note that this will go through the list returned from apt-show-versions and remove them one by one. Depending on what it finds, this could uninstall something unintended due to dependencies, so check it first.

Paul
  • 158
Egil
  • 14,522
6

Here is GUI ways to do so. Hope it would help for those who don't prefer CLI. The steps are simple and easy to follow.

  1. Open synaptic package manager. If not installed then install it by:

    sudo apt-get install synaptic
    
  2. When opened click on Origin button on down-left. It will list all the repositories on top-left side. Select the particular repository for which packages are to be removed. It will list all the packages under that repository. Click the first field i,e S or Installed Version field to show the installed packages first.

  3. Now select all packages to remove.

    Tips to mark for removal:

    1. Select first package then hold Shift key and again select the last package to select all. Then right click on the square box and select mark for removal or mark for complete removal.

    2. or Select any packages and press Ctrl+A to select all. Then right click on the square box and chose mark for removal or mark for complete removal.

That's it. It will remove without any problem. I've also attached the image to make it more clear. Hope it would help. :)

image

Saurav Kumar
  • 15,174
0

I found use of ppa-purge to be difficult.

Open Synaptic Package Manager under System, then select Settings, Repositories.

Remove the ones you don't want.

Done!

Joe
  • 1