Skip to content

How to downgrade to stock packages

Ondřej Surý edited this page Apr 23, 2020 · 1 revision

How to downgrade packages to the pristine state?

Recently, there was an issue about restoring the extra packages to the original state because the repository comes with extra libraries that stop getting the updates when the deb.sury.org repository is removed from /etc/apt/sources.list.d.

Ubuntu

On Ubuntu, it's fairly easy because Ubuntu comes with a tool called ppa-purge to accomplish that:

sudo apt install ppa-purge
sudo ppa-purge ppa:ondrej/php

Debian

On Debian, the situation is more complicated, because there's no such tool. Fortunately, apt_preferences comes to the rescue! The Pin-Priority over a 1000 will install a pinned package even if it constitutes a downgrade and Pin-Priority less than 0 will prevent packages to be installed, therefore create file called /etc/apt/preferences.d/uninstall-deb.sury.org.pref with following contents:

Package: *
Pin: release o=Debian
Pin-Priority: 1001

Package: *
Pin: release o=deb.sury.org
Pin-Priority: -1

Then run apt dist-upgrade as usual and you should get something like this (or you will get lucky and it will just work for you:

Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
Hmm, seems like the AutoRemover destroyed something which really
shouldn't happen. Please file a bug report against apt.

The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libxml2 : Depends: libicu63 (>= 63.1-1~) but it is not going to be installed
E: Internal Error, AutoRemover broke stuff

This is sort of bad, but you can now iterate through individual packages, and downgrade then one-by-one until `apt dist-upgrade:

# apt install libxml2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
  libicu65
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  libicu63
The following NEW packages will be installed:
  libicu63
The following packages will be DOWNGRADED:
  libxml2
0 upgraded, 1 newly installed, 1 downgraded, 0 to remove and 23 not upgraded.
Need to get 8987 kB of archives.
After this operation, 32.5 MB of additional disk space will be u

Fortunately, it seems that libxml2 is the only package that really breaks APT because then the apt dist-upgrade works again:

# apt dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  libargon2-1 libbsd0 libedit2 libicu65 libncurses6 libpcre16-3 libpcre2-16-0 libpcre2-32-0 libpcre2-posix2 libpcre3-dev libpcre32-3 libpcrecpp0v5 libsodium23 libssl-dev php-common php5.6-common php5.6-json php5.6-opcache php5.6-readline
  php7.0-common php7.0-json php7.0-opcache php7.0-readline php7.1-common php7.1-json php7.1-opcache php7.1-readline php7.2-common php7.2-json php7.2-opcache php7.2-readline php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline
  php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline psmisc shtool ucf
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  libpcre2-dev php-all-dev php5.6-cli php5.6-dev php7.0-cli php7.0-dev php7.1-cli php7.1-dev php7.2-cli php7.2-dev php7.3-dev php7.4-dev
The following packages will be DOWNGRADED:
  libargon2-1 libidn2-0 libpcre16-3 libpcre2-16-0 libpcre2-32-0 libpcre2-8-0 libpcre3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libsodium23 libssl-dev libssl1.1 openssl php-common php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline
0 upgraded, 0 newly installed, 20 downgraded, 12 to remove and 0 not upgraded.
Need to get 9207 kB/9284 kB of archives.
After this operation, 52.6 MB disk space will be freed.

Finally, you can autoremove the remaining cruft:

# apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  libargon2-1 libbsd0 libedit2 libicu65 libncurses6 libpcre16-3 libpcre2-16-0 libpcre2-32-0 libpcre2-posix2 libpcre3-dev libpcre32-3 libpcrecpp0v5 libsodium23 libssl-dev php-common php5.6-common php5.6-json php5.6-opcache php5.6-readline
  php7.0-common php7.0-json php7.0-opcache php7.0-readline php7.1-common php7.1-json php7.1-opcache php7.1-readline php7.2-common php7.2-json php7.2-opcache php7.2-readline php7.3-cli php7.3-common php7.3-json php7.3-opcache php7.3-readline
  php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline psmisc shtool ucf
0 upgraded, 0 newly installed, 44 to remove and 0 not upgraded.
After this operation, 95.8 MB disk space will be freed.
Do you want to continue? [Y/n]

And/or remove extra PHP versions by-hand:

# apt remove --autoremove php5*-common php7*-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'php5-common' for glob 'php5*-common'
Note, selecting 'php5.6-common' for glob 'php5*-common'
Package 'php5-common' is not installed, so not removed
Note, selecting 'php7.2-common' for glob 'php7*-common'
Note, selecting 'php7.0-common' for glob 'php7*-common'
Note, selecting 'php7.3-common' for glob 'php7*-common'
Note, selecting 'php7.1-common' for glob 'php7*-common'
Note, selecting 'php7.4-common' for glob 'php7*-common'
Package 'php7.3-common' is not installed, so not removed
Package 'php5.6-common' is not installed, so not removed
Package 'php7.0-common' is not installed, so not removed
Package 'php7.1-common' is not installed, so not removed
Package 'php7.2-common' is not installed, so not removed
Package 'php7.4-common' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.