Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Blogs > pereb
User Name


Rate this Entry

Ubuntu Package Pinning

Posted 11-19-2009 at 01:08 PM by pereb

A few weeks back I upgraded my Kubuntu installation to Karmic kaffeine version 1 came with it. Personally I would rather have kaffeine 0.8 so I decided to attempt to block updates to the package in order to use accomplish this.

The first step was to check the current version on the machine. So I needed to know the exact name of the package. In order to locate the name of the package I used the search function in apt. This returns matching packages with exact name and a short description of them. To try this out, you can use the following command: apt-cache search {searchword}.

In this case I searched for kaffeine and got the following result:

temp@folder:~$ apt-cache search kaffeine
kaffeine - versatile media player for KDE
libxine1-x - X desktop video output plugins for libxine1
kaffeine-mozilla - mozilla plugin that launches kaffeine for supported media types
w-scan - Channel scanning tool for for DVB and ATSC channels
Obviously the package I am looking for is named kaffeine. The next thing i needed to do is check which version is currently installed and which versions are available. This can be accomplished by using the command apt-cache policy packagename. So I used the command apt-cache policy kaffeine and got the following result:
temp@folder:~$ apt-cache policy kaffeine
  Installed: 1.0~pre2-0ubuntu1
  Candidate: 1.0~pre2-0ubuntu1
*** 1.0~pre2-0ubuntu1 0
        500 karmic/main Packages
        100 /var/lib/dpkg/status
This lets me know that the installed version is 1.0 and that it is the latest available version. It also tells you that that version is available from karmic/main Packages.

From there I uninstalled the currently installed version of kaffeine and downloaded the kaffeine version of my choice from apt-cache policy now returns:
  Installed: 0.8.7-1ubuntu5
  Candidate: 1.0~pre2-0ubuntu1
     1.0~pre2-0ubuntu1 0
        500 karmic/main Packages
*** 0.8.7-1ubuntu5 0
        100 /var/lib/dpkg/status
This tells me that the installed version is 0.8.7 and that the main packages offer a newer version. You don't want to update now because kaffeine 1.0 will be reinstalled. In order to prevent this from happening it's necessary to pin or hold the package.

This is pretty easy with aptitude: open a command line and type: sudo aptitude hold {packagename}. Aptitude will freeze the version to the currently installed one. This also freezes the version for all graphical interfaces, such as kpackagekit and synaptic. Pretty nifty.

Now If you are using apt-get things get a little more complicated, you'll have to pin the package. Pinning is pretty powerful, giving you much more options than simply to freezing, you can set up filters or rules about which version should be kept, when a package should be down- or upgraded and much more. A general introduction to the settings of apt and more precisely pinning can be found by entering man apt_preferences into command line.

To block a package for apt-get you need to edit /etc/apt/preferences. There you can enter the following kind of config:
Package: kaffeine
Pin: version 0.8.7*
Pin-Priority: 1000
The first line gives the package which is configured.
The second line lists what we want. The wanted package must not be defined by version, it can also be defined by release or origin or a combination of these keywords. More information can be found in your man-pages.
The third line gives the priority. Citing from the man-page:

Priorities (P) assigned in the APT preferences file must be positive
or negative integers. They are interpreted as follows (roughly

P > 1000
causes a version to be installed even if this constitutes a
downgrade of the package

990 < P <=1000
causes a version to be installed even if it does not come from the
target release, unless the installed version is more recent

500 < P <=990
causes a version to be installed unless there is a version
available belonging to the target release or the installed version
is more recent

100 < P <=500
causes a version to be installed unless there is a version
available belonging to some other distribution or the installed
version is more recent

0 < P <=100
causes a version to be installed only if there is no installed
version of the package

P < 0
prevents the version from being installed
So the config I posted earlier says that the package kaffeine with version number 0.8.7* will be installed and preferred even if the install is a downgrade. Putting that config into place and saving it (you will need SUDO powers for saving) will hold that package in the current version, so that it won't be overwritten when updates are applied.

Taking another look at the output of apt-cache policy, we can now also understand the numbers in front of the source: 100 means that this is the currently installed version, while 500, the pin-priority of the main server, means that those packages will only be installed when they are newer than the currently installed package.
Posted in Uncategorized
Views 3044 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 06:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration