Pining repositories on Debian Stretch (stable)

This process is prepared for current way how Debian is handling settings using directories.

Setting up repositories

We will start by creating /etc/apt/sources.list.d/security.list file which will be containing repositories with security updates. In addition I have enabled access to contrib and non-free repositories.

deb stable/updates main contrib non-free
deb-src stable/updates main contrib non-free
deb testing/updates main contrib non-free
deb-src testing/updates main contrib non-free

Next file on the list is /etc/apt/sources.list.d/security.list. I’m using French mirrors, because my servers are located there.

deb stable main contrib non-free
deb-src stable main contrib non-free

Now you can continue this step just bu replacing stable keyword with testing or unstable.

After this steps I suggest to comment out old entries from /etc/apt/sources.list, this will prevent from troubleshooting later.

Repository pinning

Now it is time to inform APT about preferences which repository should be used as first. This can be achieved using repository pinning. We will start for setting the highest priority for security updates. To do this just create /etc/apt/preferences.d/security.pref file with this content:

Package: *
Pin: release l=Debian-Security
Pin-Priority: 1000

Now it is time for repository with stable releases, create file /etc/apt/preferences.d/stable.pref with this content:

Package: *
Pin: release a=stable
Pin-Priority: 900

You need to repeat this with each other repositories that you have added. Remember about replacing stable keyword and lowering priority number by ex. 50.

Time to update

After this changes it is time to update repositories cache on your server. Just type sudo apt-get update in console. If you done everything properly this step should end with success.

How to use it

After this changes by default apt-get will try to install packages from stable release, then from testing etc. You can also alter this behaviour but explicit informing apt-get what repository should be used. You can do it in two ways:

# apt-get install enlightenment/unstable
 # apt-get -t unstable install enlightenment

That is all! Have fun playing