How to completely remove a third-party repository from Ubuntu

Suppose you added a third-party repository of DEB packages in your Ubuntu and you now want to completely remove it, by either downgrading the packages to the official version in Ubuntu or removing them altogether. How do you do that?

Well, if it was a Personal Package Archive (PPA), you would simply use ppa-purge. ppa-purge is not pre-installed in Ubuntu, so we install it with

sudo apt update
sudo apt install ppa-purge

Here is the help for ppa-purge:

$ ppa-purge
Warning:  Required ppa-name argument was not specified
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)
    -o [ppaowner]        PPA owner
    -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 -o xorg-edgers
    will remove https://launchpad.net/~xorg-edgers/+archive/ppa

    sudo ppa-purge -o sarvatt -p xorg-testing
    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.

Here is an example of ppa-purge that removes a PPA:
Suppose we want to completely uninstall the Official Wine Builds PPA. The URI of the PPA is shown on that page in bold, and it is ppa:wine/wine-builds.

To uninstall this PPA, we run

$ sudo ppa-purge ppa:wine/wine-builds
Updating packages lists
PPA to be removed: wine wine-builds
Package revert list generated:
wine-devel- wine-devel-amd64- wine-devel-i386:i386- winehq-devel-

Disabling wine PPA from
/etc/apt/sources.list.d/wine-ubuntu-wine-builds-xenial.list
Updating packages lists
...
PPA purged successfully
$ _

But how do we completely uninstall the packages of a third-party repository? Those do not have a URI that is similar to the format that ppa-purge needs!

Let’s see an example. If you have an Intel graphics card, you may choose to install their packaged drivers from 01.org. For Ubuntu 16.04, the download page is https://01.org/linuxgraphics/downloads/intel-graphics-update-tool-linux-os-v2.0.2  Yes, they provide a tool that you run on your system and performs a set of checks. Once those checks pass, it adds the Intel repository for Intel Graphics card drivers. You do not see a similar URI from this page, you need to dig deeper after you installed them to find out.

The details of the repository are in /etc/apt/sources.list.d/intellinuxgraphics.list and it is this single line

deb https://download.01.org/gfx/ubuntu/16.04/main xenial main #Intel Graphics drivers

How did we figure out the parameters for ppa-purge? These parameters are just used to identify the correct file in /var/lib/apt/lists/ For the case of the Intel drivers, the relevant files in /var/lib/apt/lists are

/var/lib/apt/lists/download.01.org_gfx_ubuntu_16.04_main_dists_xenial_InRelease
/var/lib/apt/lists/download.01.org_gfx_ubuntu_16.04_main_dists_xenial_main_binary-amd64_Packages
/var/lib/apt/lists/download.01.org_gfx_ubuntu_16.04_main_dists_xenial_main_binary-i386_Packages

The important ones are the *_Packages files. The important source code line in ppa-purge that will help us, is

PPA_LIST=/var/lib/apt/lists/${PPAHOST}_${PPAOWNER}_${PPANAME}_*_Packages

therefore, we select the parameters for ppa-purge accordingly:

-s download.01.org   for   ${PPAHOST}
-o gfx               for   ${PPAOWNER}
-p ubuntu            for   ${PPANAME}

Now ppa-purge can remove the packages from such a PPA as well, by using these parameters:

sudo ppa-purge -s download.01.org -o gfx -p ubuntu

That’s it!

Leave a Reply

%d bloggers like this: