How to disable non-Ubuntu repositories and remove the packages installed from them?

4. Return your deb sources and packages to stock condition

Disable all non-Ubuntu (unoficial) deb sources, including disabling PPAs. Uninstall the deb packages that those sources provided. Return your deb packages to as close to stock condition as possible.

  • Keep deb packages that came from the official Ubuntu repositores. Those are supported.

  • Keep non-deb software, like Snaps, Brews, Flatpaks, Wheels, etc. We can’t guarantee that they will work under 26.04, but they won’t break the release-upgrade.


Whilst the above is a great recommendation, I am left hanging as to how to achieve it. To help others, here’s what I got so far. There may be better ways to achieve this.

  1. Disabling non-ubuntu sources.

I think you can officially find your sources in /etc/apt/sources.list.d/ folder and /etc/apt/sources.list file. But GUI package managers should also offer an easy way to disable sources. In Kubuntu/KDE’s Discover it looks like this:

I think that anything under “Ubuntu XX.XX” that’s not named “Ubuntu Questing …” should be disabled

  1. Listing all manually installed non-ubuntu packages

You can very easily list all the packages marked as “manually installed” using apt-mark showmanual. This is a good list to keep in mind and save to a file. If you have to re-install everything, it’ll make your life much easier.

However, right now we only care about those that come from a “third party source”. I had a coding agent produce the following bash script which looks at the result of apt-cache policy <pkg>:

apt-mark showmanual | while read -r pkg; do
    if apt-cache policy "$pkg" | grep -Eq '^[[:space:]]+[0-9]+ http(s)?://([^ ]*ubuntu\.com|[^ ]*canonical\.com)/'; then
        :
    else
        echo "$pkg"
    fi
done

At a quick glance, the result look good enough for me. (lists only apps I did install from custom sources)

Save that list to a file so you can easily add them back later.

  1. You can now uninstall all those packages with sudo apt remove <pkg>
  2. Those packages had dependencies, that are likely also no longer needed, and we don’t want them to be in the way of the system upgrade. So sudo apt autoremove to clean that up.

Additional note: As for non-debs, I don’t use Brews, Snaps, Wheels, or whatever. Only flatpaks, which are all user-installed (not system-installed) and my Home partition is on its own drive. Which makes it quite easy to keep my apps across Distros.

Please let me know if I got anything wrong! Official recommendations would be welcome here !

Also not that as of writing this, my release window isn’t open yet (you can check if a new release is available without committing to it with do-release-upgrade -c). So I have not actually gone through the disable/uninstall steps myself as of yet.

3 Likes

That pattern matches any URL with “ubuntu.com” in it, even “http://foo.bar/archive/ubuntu.com/”. Matching the repository URL is also brittle, in general, because of mirrors on different domains.

Long story short, you can uninstall any manually installed 3rd-party packages with plain apt and the help of apt-patterns, all in one go:

apt remove '~i!~M!~O^Ubuntu$'
  • ~i matches installed packages
  • !~M matches not (!) automatically installed ones
  • !~O matches the ones whose “Origin:” field doesn’t match “Ubuntu”, exactly

If you want to save the list for later re-installation just redirect the apt list command to a file:

apt list '~i!~M!~O^Ubuntu$'

P.S.: Only removing the manually installed 3rd party packages will leave any automatically installed ones in place, unless followed up by apt autoremove. And it may still leave you with others which have a reverse dependency; another package depending on them. So one should follow up with

apt remove '~i!~O^Ubuntu$'

you can remove revert packages and remove PPAs with ppa-purge

You may see that many PPAs listings in launchpad refer to this tool for this purpose.

Often PPAs have updated versions of standard software. ppa-purge will revert to the version in the standard repo (if it finds this), then it removes the ppa. When you run ppa-purge, make sure you don’t have open any tool that blocks something else from changing installed packages (e.g. synaptic). It’s a good tool, but getting the name of repository to purge can be a big tricky. chatgpt or gemini is your friend.

Since I’ve only just recently learnt about that one, myself, does it support purging packages from any package repo type, not just PPAs?

Nice idea. If only there weren’t intersections. The problem here is packages that have the same name in both sources. For example, if firefox is installed from the mozilla package source, then you can positively expect the following:

col@row:~$ apt list "?installed ?origin(mozilla)" 
firefox-l10n-de/mozilla,now 150.0.1~build1 all [installed] 
firefox/mozilla,now 150.0.1~build1 amd64 [installed] 
col@row:~$

But this output is a bit unexpected:

col@row:~$ apt list "?installed ?origin(ubuntu)" 2> /dev/null | grep firefox 
firefox/mozilla,now 150.0.1~build1 amd64 [installed] 
col@row:~$

Two lists are compared and only the entries that appear in both lists are mentioned. Yes, firefox is installed and yes, there is a firefox from Ubuntu. So it goes into the output. Unfortunately there is a second package with the same name and this is installed. However, the logic of apt-patterns does not go that far.

Accordingly, with apt list '~i!~M!~O^Ubuntu$', firefox was not displayed, but only its language package, which is only available from mozilla.

@Avasam’s approach gives equally wrong results.

So it doesn’t help. With apt-cache you can query all third-party sources (origins) and search for them specifically. Packages that only come from Ubuntu are therefore excluded. As far as I know, for the rest you have to go through everything manually.

So using third-party sources sparingly means there is less rework.


PS:
Rethinking: If the following is empty, then it is a installed foreign deb-package:
apt-cache policy firefox | grep -A1 "\*\*\*" | tail -1 | grep "ubuntu $(lsb_release -cs 2>/dev/null)"
make it better :wink:

1 Like

This works for me
$ apt list '~i?narrow(!~Oubuntu!?phasing)'

bleachbit/now 6.0.0-0 all [installed,local]
brscan5/now 1.5.1-0 amd64 [installed,local]
debian-goodies/now 0.88.2ubuntu1 all [installed,local]
focuswriter/noble,now 1.9.0-0ppa1~noble amd64 [installed]
gdebi-core/now 0.9.5.8 all [installed,local]
gdebi/now 0.9.5.8 all [installed,local]
homebank-data/noble,now 5.10.0-0~202604091958~ubuntu24.04.1 all [installed,automatic]
homebank/noble,now 5.10.0-0~202604091958~ubuntu24.04.1 amd64 [installed]
keepassxc/noble,now 2.7.12-1ppa1~noble1 amd64 [installed]
oracle-java8-jre/now 8u491 amd64 [installed,local]
virtualbox-7.2/unknown,now 7.2.8-173730~Ubuntu~noble amd64 [installed]

On my 24.04 system, I have bleachbit, brscan5 (brother scanner driver), debian-goodies (from questing), gdebi and gdebi core (from questing) and oracle-java8-jre as locally installed debs.

Focuswriter, homebank, keepassxc, and virtualbox-7.2 are installed from ppa’s and the Oracle virtualbox apt repostitory.

Focuswriter, homebank and keepassxc all have packages in Ubuntu’s archives (“intersections” as you put it). Virtualbox package name is the archive but not Virtualbox-7.2

I had to put “!?phasing” in because if isn’t in there phasing packages show up in the list.

3 Likes

Useful! But mostly over my head. Where is the best place to look for an idiot’s guide to “returning your deb sources and packages to stock condition”?

There isn’t one. But, if all you want is to get rid of non-Ubuntu packages, you just need to disable all 3rd party repos and run sudo apt upgrade --update[1]. That should give you the latest official packages. After that you just need to find orphaned packages, i.e. “packages no longer available for download”. You can use APT patterns for that, or you can explore the excellent aptitude TUI:

$ sudo apt install aptitude
$ aptitude

Then open the “Obsolete and Locally Created Packages” category.


  1. not quite, because that won’t downgrade to lower version numbers without some apt magic ↩︎

If you mean after using/removing a PPA, there is a guide for that here.

1 Like

But not every non-Ubuntu repo is a PPA. I did ask if ppa-purge works with regular repos too, but didn’t get an answer.

The answer is no.

The ppa-purge tool expects a specific PPA Launchpad format in order to do its thing.

1 Like

Thank you for that. What I’m after is a clear guide to what to do before upgrading from Ubuntu 25.10 to 26.04. The guide I read said to “return your deb sources and packages to stock condition”, and I’m simply looking for a clear and easily understandable (to a non-techy person) guide to doing that.

during first install, there used to be a /var/log/installer/initial-status.gz

I can find it in my u24 but not in my u26.

There is no “non-techy” way to remove non-Ubuntu deb packages. Installing non-Ubuntu software is already off-path and “techy.” But people do it anyway, and this is the consequence.

One easily-understandable way is to start with sources:

  • Run sudo apt update.
  • Read, line by line, the list of sources. Are any of them unofficial or not-Ubuntu?
  • Search your memory for each of those non-Ubuntu sources: Why did you add it? What did you install from that non-Ubuntu source?
  • Use apt to uninstall that non-Ubuntu deb. Include autoremove so that related dependencies also get removed.
    Reminder: When using autoremove, ALWAYS read and understand the suggested removals before agreeing. A poorly-configured system might try to remove far more than you expect. You’ve been warned!
  • Finally, disable or delete the non-Ubuntu source.
2 Likes

Thank you @ian-weisser

This looks manageable! Much appreciated.

1 Like