Debian: programs from stable, testing, unstable and even experimental without trauma

I originally wrote this in Italian but I think that it may be more useful translated into English

In daily use of computers it often happens that you need a stable base and at the same time use recent, very recent or even ‘beta/alpha/experimental’ versions of some specific programs.

Debian users are no less, indeed! It also apply to all its derivatives, starting from Ubuntu.

Matteo Galacci suggest (in an italian article) – like many others – to use Debian’s “pinning” capability.

In reality, if the need is to have ‘almost all’ stable programs, some more recent and a few ‘very recent’ it is possible to obtain this behavior by exploiting the basic algorithm of the Debian package manager apt. Consulting the man-pages that tells us how to set up our sources (man sources.list) we read:

The source list /etc/apt/sources.list and the files contained in /etc/apt/sources.list.d/ are designed to support any number of active sources and a variety of source media. The files list one source per line (one-line style) or contain multiline stanzas defining one or more sources per stanza (deb822 style), with the most preferred source listed first (in case a single version is available from more than one source). The information available from the configured sources is acquired by apt-get update (or by an equivalent command from another APT front-end).

The ‘trick’ is in the part in bold. Matteo first proposes testing, then unstable and finally stable. So apt will almost never choose stable releases. I use a /etc/apt/sources.list like this:

deb http://ftp.it.debian.org/debian/ stable main contrib non-free
# stable-updates, previously known as 'volatile'
deb http://ftp.it.debian.org/debian/ stable-updates main contrib non-free
# if something is not in stable look in testing
deb http://ftp.it.debian.org/debian/ testing main contrib non-free
# then search for it in unstable 
deb http://ftp.it.debian.org/debian/ unstable main contrib non-free
# as an extrema ration look in experimental
deb http://ftp.it.debian.org/debian/ experimental main contrib non-free

Putting stable first, and then testing, unstable and also experimental in this order

So when we don’t need particular versions, just ask for ‘apt install package‘ and the most stable version possible will be chosen: if it’s in stable, otherwise it will take the one in testing, therefore it will search into unstable and finally experimental.

Easy, fast, practical. And above all it works, and it works well. With this APT setup, I’ve been using the Radeon card drivers from experimental for years without any other programs being upgraded to experimental versions.

Then if we wanted a particular version just run ‘apt install package unstable‘ and the unstable one will be installed.

In the case of updates, APT will remember our choice and continue to update the ‘package’ from the source indicated by us. If over time the version we wanted should (as we all hope) enter testing and then stable, just re-launch ‘apt install package/stable‘ to go back to updating from stable.

If we then wanted to ‘go down’ in version just add an --allow-downgrade.

6 Replies to “Debian: programs from stable, testing, unstable and even experimental without trauma”

  1. This is very interesting!
    … but wrong.

    The order in sources.list decides where to get a package from, not which package version to install.
    I just tried it by removing my preferences and having stable first, and it wants to upgrade 3042 packages. After reenabling preferences, it is back to 0.

    You can conclude this from the man page you cited, too, by just reading on: ” It is important to list sources in order of preference, with the most preferred source listed first. Typically this will result in sorting by speed from fastest to slowest (CD-ROM followed by hosts on a local network, followed by distant Internet hosts, for example).”

    1. It has been working for me on several machines since at least a decade… I just rechecked on the freshly installed machine I’m writing from and worked as I intended.

      1. One of us is doing something wrong…

        Here’s my transcript (shortened by some thousand packages 😉 )…

        root@track:/etc/apt# cat /etc/apt/sources.list
        deb http://deb.debian.org/debian/ bookworm main non-free non-free-firmware contrib
        deb http://deb.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
        deb http://deb.debian.org/debian bookworm-updates main contrib non-free non-free-firmware
        deb http://deb.debian.org/debian bookworm-backports main contrib non-free non-free-firmware
        deb http://deb.debian.org/debian testing main contrib non-free non-free-firmware
        deb http://deb.debian.org/debian unstable main contrib non-free non-free-firmware
        deb http://deb.debian.org/debian experimental main contrib non-free non-free-firmware

        root@track:/etc/apt# apt update
        OK:1 http://deb.debian.org/debian bookworm InRelease
        OK:2 http://deb.debian.org/debian-security bookworm-security InRelease
        OK:3 http://deb.debian.org/debian bookworm-updates InRelease
        OK:4 http://deb.debian.org/debian bookworm-backports InRelease
        OK:5 https://updates.signal.org/desktop/apt xenial InRelease
        OK:6 http://deb.debian.org/debian testing InRelease
        OK:7 http://deb.debian.org/debian unstable InRelease
        OK:8 http://deb.debian.org/debian experimental InRelease
        Paketlisten werden gelesen… Fertig
        Abhängigkeitsbaum wird aufgebaut… Fertig
        Statusinformationen werden eingelesen… Fertig
        Alle Pakete sind aktuell.

        root@track:/etc/apt# apt list –upgradable
        Auflistung… Fertig

        root@track:/etc/apt# mv preferences.d/ preferences.d.bak

        root@track:/etc/apt# LANG=C apt upgrade
        Reading package lists… Done
        Building dependency tree… Done
        Reading state information… Done
        Calculating upgrade… Done
        [……………]
        The following packages will be upgraded:
        adduser adwaita-icon-theme alsa-topology-conf anacron apg apper-data apt-config-icons apt-config-icons-hidpi apt-config-icons-large
        [……………]
        xserver-xorg-video-vesa xserver-xorg-video-vmware xxd xz-utils yelp-xsl yt-dlp zenity-common zip zlib1g zlib1g:i386 zlib1g-dev
        1093 upgraded, 52 newly installed, 0 to remove and 1948 not upgraded.
        Need to get 855 MB/865 MB of archives.
        After this operation, 326 MB of additional disk space will be used.
        W: Unable to read /etc/apt/preferences.d/ – DirectoryExists (2: No such file or directory)
        Do you want to continue? [Y/n]
        [no thanks!]

        root@track:/etc/apt# mv preferences.d.bak/ preferences.d

        root@track:/etc/apt# LANG=C apt upgrade
        Reading package lists… Done
        Building dependency tree… Done
        Reading state information… Done
        Calculating upgrade… Done
        The following packages were automatically installed and are no longer required:
        linux-headers-6.12.9+bpo-common linux-kbuild-6.12.9+bpo
        Use ‘apt autoremove’ to remove them.
        0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

      2. Sorry, third reply here… Did you get my apt transcript? It seems wordpress ate up more than its line breaks?

        1. Sorry Eike, I missed your comments!
          I am not saying you are wrong, I wrote what it just work for me. I suspect that my way of doing does not mix well with preferences.d.
          What’s the content of your preferences.d?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.