个人工具

UbuntuHelp:PinningHowto

来自Ubuntu中文

跳转至: 导航, 搜索

This wiki page will discuss some advanced things you can do to packages to accomplish specific goals. The first thing described is Pinning, this is useful if you want only some things from a newer version of Ubuntu. There is also package holding, which allows you to not update the package.

Introduction to Pinning

Pinning is a process that allows you to remain on a stable release of Ubuntu (or any other debian system) while grabbing packages from a more recent version. Note however that the processes described below will only work if things like libc6 versions match, so you should probably not do this on an Ubuntu system. I strongly recommend you look at UbuntuBackports before doing this.

Pinning Methods

There are 3 main files you must edit for pinning to even function. It is important to start out by setting your default release to avoid accidentally upgrading all packages, by editing /etc/apt/apt.conf [in intrepid that is /etc/apt/apt.conf.d/01ubuntu, "intrepid" rather than "hardy"] as follows:

APT::Default-Release "hardy";

The second file is: /etc/apt/sources.list An example configuration is as follows:

# official ubuntu sites
deb http://archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu intrepid main restricted universe multiverse

In this example, we're pulling from hardy and intrepid (the current development version of Ubuntu). The next file involved is: /etc/apt/preferences The 'preferences' file is where the actual pinning takes place. To pin a package, set its Pin-Priority to higher number. Here's an example:

Package: firefox-3.0
Pin: release a=hardy
Pin-Priority: -10

Package: firefox-3.0
Pin: release a=intrepid
Pin-Priority: 900

In this example, we're giving a higher priority to Firefox from intrepid because we want rc1 instead of beta5. This of course can be done with any package, or even all packages - although in the above example, you likely want to change hardy and intrepid Pin-Priority values around so that hardy is default. For further information please read: man apt_preferences

Debugging Package Priorities

To print out the priorities of each source, run `apt-cache policy`. For priorities for packages, run `apt-cache policy packagename[s]`.

Recommended alternative to pinning

In Ubuntu, most times, the libc6 version is updated from version to version - it is not the purpose of this page to describe what libc6 is, but needless to say it breaks the above example. A better method for grabbing things from a development version while not committing your entire machine to that version is as follows: Add the following line to /etc/apt/sources.list

deb-src http://archive.ubuntu.com/ubuntu intrepid main restricted universe multiverse

Then you'll need to update your repos:

sudo apt-get update 

Now we need to install some packages so we can build the desired software in intrepid:

sudo apt-get build-dep firefox-3.0

Now we can do the following to get the package built from intrepid on our hardy machine:

sudo apt-get -b source -t intrepid firefox-3.0

It will output lots of info on the screen, when it's done (could take a while), you will have rc1 instead of beta5!

Introduction to Holding Packages

Holding a package basically means you're telling the package manager to keep the current version no matter what. This is useful if more recent version of a currently working program breaks after an update. The following will describe the process of actually holding the package, there are several options to accomplish this:

Synaptic

PinningHowto?action=AttachFile&do=get&target=lockver.png

First way to hold a package is in Synaptic:

  • Open Synaptic: System -> Administration -> Synaptic Package Manager
  • Click Search and type the package's name in the Search box
  • Highlight the version you want to pin Make sure that you select the correct version
  • Once the correct package is selected, Click Package -> Lock Version
  • Close Synaptic

<
>

Apt/Dpkg

Second way is to hold it with Apt/Dpkg:

  • Open a terminal
  • sudo -s and hit enter
  • Enter your password for sudo
echo libxfont1 hold | dpkg --set-selections
Replace libxfont1 with the package you want to pin
  • Now run sudo apt-get update and then sudo apt-get upgrade

Removing a Hold

To remove a package from hold, you can run "sudo apt-get install libxfont1" (replacing libxfont1 with the package you wish to remove). To see what the next version of the package is, use `apt-cache policy packagename` (see Debugging Package Priorities above).

Synaptic

To remove the pin in Synaptic:

  • Open Synaptic
  • Search for the correct package
  • Click on package to highlight it
  • Once the correct package is selected, Click Package -> Lock Version to remove the checkmark
  • Close Synaptic

Apt/Dpkg

To remove pin from Apt/Dpkg:

  • Open a terminal
  • sudo -s and hit enter
  • Enter your password for sudo
echo libxfont1 install | dpkg --set-selections Replace libxfont1 with the package you want to pin
  • Now run sudo apt-get update and then sudo apt-get upgrade

NOTE At the time of the making this Wiki there is not a known way to Pin a package with Update Manager. Pinning should never be used for installing Debian binary packages on Ubuntu. Ubuntu strongly recommends against using Debian binary packages on Ubuntu,

Karmic Example

Pinning the ubuntu-mozilla-daily PPA

"I regularly use a package from the Ubuntu Daily Mozilla PPA. Unfortunately the PPA also contains snapshot builds of Firefox 3.5 and XulRunner 1.9.1, which I want to keep at their standard Ubuntu versions". The Pinning Solution To make apt-get upgrading as painless as possible set a lower Pin-Priority on the PPA, this will stop unwanted package versions from installing. Once set, packages from the ubuntu-mozilla-daily PPA will always lose in any contest with packages from other repositories, even if they have a higher version. Create the file:

  1. /etc/apt/preferences.d/ubuntu-mozilla-daily-pin-400
  2. Add the following to the file:

Code:

      Package: *
      Pin: release o=LP-PPA-ubuntu-mozilla-daily
      Pin-Priority: 400

Use the following commands, before and after, to check that the Pin-Priority has been updated.

apt-cache policy
apt-cache policy firefox-3.5

Make sure the file name does not have a dot in it!

Links

These documents were used as a foundation for this page, and might give you more background information: