HowTo: Debian Apt Pinning And Upgrading To Other Branches

Recently I’ve been quite busy on a number of side projects. While working on one of the projects I was helping someone else understand it. That led me to trying to explain pinning.

Pinning is extremely simple and needed for different branches of a project, or using other repositories. Let’s say you have Debian Stable installed and want to use the just released Firefox 5 (Iceweasel 5), you can. You would setup pinning to help control your repositories. That’s another benefit of pinning, you easily control what gets installed from what repositories, thus you’re able to have more repositories listed in your sources.list file without the worry of one superseding the other.

Hopefully the example to follow will explain a bit better than I can here.

First let’s setup our sources.list file to point at all of Debian’s branches, experimental, unstable, testing, stable.

deb http://ftp.ca.debian.org/debian/ stable main
deb-src http://ftp.ca.debian.org/debian/ stable main

deb http://ftp.ca.debian.org/debian/ testing main
deb-src http://ftp.ca.debian.org/debian/ testing main

deb http://ftp.ca.debian.org/debian/ unstable main
deb-src http://ftp.ca.debian.org/debian/ unstable

deb http://ftp.ca.debian.org/debian/ experimental main
deb-src http://ftp.ca.debian.org/debian/ experimental main

(Note: This is just an example as the above mirrors are located in Canada. Change them accordingly as needed. Also, since this is to give a basic understanding I left out some other important mirrors, updates, etc.)

Now that we’ve got those setup we need to do a bit of tweaking to apt since it has a cache limit. What that means is that the more repositories you add the closer you get to reaching that limit and making apt pout and quit. Also, as a recommendation, with any Debian based system I would add at least one more repository entry for each branch as a fallback. I’d actually add two or three more. That increases apt’s cache as you’d guess. Just some advice, and another reason why setting the cache is important.

Point your favourite editor to /etc/apt/apt.conf and open the file, or create it if it doesn’t already exist.

Now add this to the file: APT::Cache-Limit “80000000”;

Then save the file and exit the editor.

If you ever have a problem with too many repositories just increase the cache limit.

It’s time to setup pinning.

Point your favourite editor to /etc/apt/preferences and open the file, or create it if it doesn’t already exist.

Now add this to the file:

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

Package: *
Pin: release a=testing
Pin-Priority: 600

Package: *
Pin: release a=unstable
Pin-Priority: 550

Package: *
Pin: release a=experimental
Pin-Priority: 500

Then save and exit, and update with: apt-get update

What the above does is gives you total control over the repositories. Debian Stable takes priority since it has the highest value of 700, then Testing, Unstable, and Experimental.

You could easily change it around to using Unstable as your main system and have Testing and Stable pinned for any needed dependencies, or any extra stable packages with security updates if needed.

Also, another explanation is needed here. The first line for each entry is packages. The asterisk lets apt know that it’s for all packages. You can have it set to install any single package (or group of packages) with the package name. Since I know all of you are extreme command line users I’m sure you’ll want the latest version of moon-buggy installed. To do this you would just put the package name there.

Here’s the example:

Package: moon-buggy
Pin: release a=unstable
Pin-Priority: 550

To install packages from the pinned repositories just use this command:

apt-get -t unstable install moon-buggy

As I’ve said earlier, you could use this to install unstable by setting unstable to have the highest pin priority then testing after it, and finally stable.

Here’s my recommended way to upgrade to unstable from either stable or testing, after setting up the proper pinning priority of course.

Issue these commands in a terminal:

apt-get update
apt-get upgrade
apt-get dist-upgrade
apt-get clean
apt-get autoclean
apt-get autoremove

You might wonder why I say to run upgrade before dist-upgrade, or even at all. The answer is easy, and a preference. Various times you can run a dist-upgrade and have absolutely no problems. Other times it can be full of broken packages. I believe that running apt-get upgrade first lessens the likelyhood of that happening. That’s just opinion though.

Also on that note, upgrade from the most basic install possible if you can. Even better, do it from a clean install. Get your hands on a Debian testing CD and install only the base system. Then make the appropriate changes to your repositories, and setup pinning. Once this is done run the above commands to upgrade to unstable. After that you can run tasksel on the command line and install any package groups as needed, for example, desktop. That’s the cleanest way I know to make the switch, and the only way I’d recommend to.

Hope that helps someone. Any questions at all feel free to ask them in the comments below.

Keep your stick on the ice…

Landor

This entry was posted in GNU/Linux, Howtos and tagged , , , , , , . Bookmark the permalink.

2 Responses to HowTo: Debian Apt Pinning And Upgrading To Other Branches

  1. tdockery97 says:

    “I believe that running apt-get upgrade first lessens the likelyhood of that happening. That’s just opinion though.”

    It’s my opinion (and experience) as well. When I update my Debian Testing I always use the full command: sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade. By running it in this order I end up with no broken packages.

  2. samuel says:

    Landor, just don’t know in which forum to put this question that is about knowledge of how computers work, not on how to do a particular thing. I am using Debian squeeze, gnome. I downloaded the compressed folder of firefox5, and the extracted it on Desktop and copied the new folder in the home directly. Openin the new folder I saw that by clicling a firefox file within the folder, firefox5 was opening and I was able to browse using it. At no point did I have to type user password. My question now is, is firefox5 installed in my system? I guess the answer is no because I only did a simple copy paste of the folder. But then since firefox5 is working in my computer, what did I do if that’s not installing it?
    Is it more risky to browse using such a browser whose content only sits on the home browser?
    Samuel, Italy.
    Regards.

Leave a comment