个人工具

“UbuntuHelp:PinningHowto”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/PinningHowto}}
 
{{From|https://help.ubuntu.com/community/PinningHowto}}
 
{{Languages|UbuntuHelp:PinningHowto}}
 
{{Languages|UbuntuHelp:PinningHowto}}
=== Introduction and Pointers to better docs ===
+
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.
First of all, I want to recommand to remove the sections below this one - the explanantions below are, in my opinion, hard to understand and point into wrong directions - even for people who know how pinning works and have a working setup.  
+
== Introduction to Pinning ==
Pinning is a solution to be able to install packages from different Ubuntu releases on an Ubuntu system, without completely "polluting" your system with libraries and applications that are not meant for the version you are actually running.
+
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.
In other words: if you are running Ubuntu Dapper and need a newer version of a single program or want to run an app that is only available on Ubuntu Edgy, apt pinning might be the solution for you.
+
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 [[UbuntuHelp:UbuntuBackports|UbuntuBackports]] before doing this.
It helps you to only install the app you need, and, if needed its dependencies, from a repository that is made for another Ubuntu version.
+
=== Pinning Methods ===
It might also work when you want to install an older version of a program on a newer version of ubuntu - just change the priorities/release appropriately.
+
There are 3 main files you must edit for pinning to even function.
Pinning should not be used for installing Debian binary packages on Ubuntu.
+
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:
I strongly recommend against using Debian binary packages on Ubuntu, unless you know very well what you are doing - in case a package you need is only available in Debian, you should definitely try to build the package from Debian sources on Ubuntu as a first priority. In this case you don't need pinning.
+
If you are new to the topic, here are two pointers to Howto's that get you up and running in some simple steps:
+
* This link contains a very good description of what pinning is and how it works: [http://wiki.serios.net/wiki/Apt-Pinning_on_Ubuntu]
+
* And this is a very good and short introduction to pinning on Debian - for using it in Ubuntu one will have to adapt the release names in the sources.list and in the preferences file to Ubuntu release names: [http://jaqque.sbih.org/kplug/apt-pinning.html]
+
One thing that's not mentioned in the Ubuntu Howto, is the Error:
+
 
<pre><nowiki>
 
<pre><nowiki>
Reading package lists... Error!
+
APT::Default-Release "hardy";
E: Dynamic MMap ran out of room
+
 
</nowiki></pre>
 
</nowiki></pre>
and the amount of added cache described in the Debian Howto is not enough.  
+
The second file is:
 +
/etc/apt/sources.list
 +
An example configuration is as follows:
 
<pre><nowiki>
 
<pre><nowiki>
echo "APT::Cache-Limit 16777216;" >> /etc/apt/apt.conf
+
# 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
 
</nowiki></pre>
 
</nowiki></pre>
should help.
+
In this example, we're pulling from hardy and intrepid (the current development version of Ubuntu).
Another thing that's not mentioned in the Howto is what pin-priorities you can use. Setting to high a priority may not result in the desired effect. See https://help.ubuntu.com/community/UbuntuBackports#head-0b2a1029f552e385c1af0dc485bf14bcc4ebd5bc for examples and explanations.
+
The next file involved is:
=== here the ancient article on pinning starts ===
+
/etc/apt/preferences
!!!!!!!!!!!!!!!!!!! Attention !!!!!!!!!!!!!!!!!!!
+
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:
The nomenclature in the Release files (stored in /var/lib/apt/lists/) seems to have changed without notice and without the necessary adaptions of the man files as well as apt-show-versions.
+
This seems to lead to major implications with the apt package manager especially if you leave your old /etc/apt/preferences file untouched. How to edit it does not seem to be documented anywhere however!
+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
Usually people follow one of the versions of Ubuntu, you either run Ubuntu 5.04 (Hoary Hedgehog) or Ubuntu 5.10 (Breezy Badger), but sometimes you would like to do more. Or despite the fact that everybody says you shoudn't do it, you want to add packages from Debian sid. If that is you, then read on...
+
=== Contents ===
+
* How to keep a mixed system
+
* How to upgrade packages from specific versions of Ubuntu
+
* How to keep specific versions of packages installed (complex)
+
* An example /etc/apt/sources.list
+
* Links
+
=== How to keep a mixed system ===
+
People are sometimes interested in using one of the Debian versions as its main system distribution and one or more packages from another branch.
+
To set up what is your main version of Ubuntu you should edit the /etc/apt/apt.conf to contain the following line (you may need to create it):
+
 
<pre><nowiki>
 
<pre><nowiki>
  APT::Default-Release "version";
+
Package: firefox-3.0
 +
Pin: release a=hardy
 +
Pin-Priority: -10
 +
 
 +
Package: firefox-3.0
 +
Pin: release a=intrepid
 +
Pin-Priority: 900
 
</nowiki></pre>
 
</nowiki></pre>
Where version is the version of Ubuntu you want to use as the main distribution. The versions you can use are Ubuntu 5.04 (Hoary Hedgehog), Ubuntu 5.10 (Breezy Badger) or a later release name. To install packages from another version, then, you must use APT in the following way:
+
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
 
<pre><nowiki>
 
<pre><nowiki>
  sudo apt-get -t <distribution> install package
+
deb-src http://archive.ubuntu.com/ubuntu intrepid main restricted universe multiverse
 
</nowiki></pre>
 
</nowiki></pre>
For that to work, though, you need at least one APT source line in your /etc/apt/sources.list for the distribution you want the package from, and the package must exist on that source. See An example /etc/apt/sources.list, below.
+
Then you'll need to update your repos:
You can also request a specific version of a package using the following syntax:
+
 
<pre><nowiki>
 
<pre><nowiki>
  sudo apt-get install package=version
+
sudo apt-get update
 
</nowiki></pre>
 
</nowiki></pre>
For example, the line below will install version 2.2.4-1 of the nautilus package.:
+
Now we need to install some packages so we can build the desired software in intrepid:
 
<pre><nowiki>
 
<pre><nowiki>
  sudo apt-get install nautilus=2.11.2-0ubuntu1
+
sudo apt-get build-dep firefox-3.0
 
</nowiki></pre>
 
</nowiki></pre>
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconWarning3.png ''IMPORTANT:''
+
Now we can do the following to get the package built from intrepid on our hardy machine:
* the *unstable* version of Ubuntu is the version that is currently in development. This distribution sees all of the changes that packages go through, both small ones and more drastic ones which affect many packages or the whole system. For this reason, this version of the distribution should not be used by inexperienced users or by those who need proven stability.
+
=== How to upgrade packages from specific versions of Ubuntu ===
+
Apt-show-versions provides a safe way for users of mixed distributions to upgrade their systems without getting more of the less-stable distribution than they had in mind. For instance, it is possible to upgrade just your Hoary packages by running after having installed the apt-show-versions package:
+
To install apt-show-versions:
+
 
<pre><nowiki>
 
<pre><nowiki>
  sudo apt-get install apt-show-versions
+
sudo apt-get -b source -t intrepid firefox-3.0
 
</nowiki></pre>
 
</nowiki></pre>
To upgrade packages from hoary:
+
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 ===
 +
{|border="1" cellspacing="0"
 +
| https://help.ubuntu.com/community/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
 +
<<BR>>
 +
=== Apt/Dpkg ===
 +
Second way is to hold it with Apt/Dpkg: 
 +
*Open a terminal
 +
*sudo -s and hit enter
 +
*Enter your password for sudo
 
<pre><nowiki>
 
<pre><nowiki>
  sudo apt-get install `apt-show-versions -u -b | grep hoary`
+
echo libxfont1 hold | dpkg --set-selections
</nowiki></pre>
+
</nowiki></pre> '''Replace libxfont1 with the package you want to pin'''
=== How to keep specific versions of packages installed (complex) ===
+
*Now run sudo apt-get update and then sudo apt-get upgrade
You may have occasion to modify something in a package and don't have time or don't want to port those changes to a new version of the program. Or, for instance, you may have just upgraded your Ubuntu distribution to Ubuntu 5.10 (Breezy Badger), but want to continue with the version of a certain package from Ubuntu 5.04 (Hoary Hedgehog). You can "pin" the version you have installed so that it will not be upgraded.
+
== Removing a Hold ==
Using this resource is simple. You just need to edit the file /etc/apt/preferences.
+
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).
The format is simple:
+
=== 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
 +
*<pre><nowiki>
 +
echo libxfont1 install | dpkg --set-selections
 +
</nowiki></pre> '''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:
 +
<ol><li>/etc/apt/preferences.d/ubuntu-mozilla-daily-pin-400
 +
</li><li>Add the following to the file:</li></ol>
 +
 
 +
Code:
 
<pre><nowiki>
 
<pre><nowiki>
  Package: <package>
+
      Package: *
  Pin: <pin definition>
+
      Pin: release o=LP-PPA-ubuntu-mozilla-daily
  Pin-Priority: <pin's priority>
+
      Pin-Priority: 400
 
</nowiki></pre>
 
</nowiki></pre>
For example, to keep package sylpheed that I have modified to use "reply-to-list" at version 0.4.99, I add:
+
Use the following commands, before and after, to check that the Pin-Priority has been updated.
 
<pre><nowiki>
 
<pre><nowiki>
  Package: sylpheed
+
apt-cache policy
  Pin: version 0.4.99*
+
 
</nowiki></pre>
 
</nowiki></pre>
Note that I used an * (asterisk). This is a "wildcard"; it say that I want that this "pin" to be valid for all versions beginning with 0.4.99. This is because Ubuntu versions its packages with a "Ubuntu revision" and I don't want to avoid the installation of these revisions. So, for instance, versions 0.4.99-1 and 0.4.99-10 will be installed as soon as they are made available. Note that if you modified the package you won't want to do things this way.
 
The Pin-Priority field is optional; if not specified, it defaults to 989.
 
Let's take a look at how pin priorities work. A priority lower than 0 indicates that the package should never be installed. Priorities 0 to 100 denote packages that are not installed and that have no available versions. These won't come into the version-choosing process. Priority 100 is the priority assigned to an installed package - for the installed version of a package to be replaced by a different version, the replacement must have a priority greater than 100.
 
Priorities above 100 indicate that a package should be installed. Typically, the installed version of a package is changed only to upgrade it to a newer version. Any priority between 100 and 1000 (inclusive) indicates this typical behavior. A package with such a priority will not downgrade to an available version with a lower version number. For instance, if I have sylpheed 0.5.3 installed and define a pin on sylpheed 0.4.99 with priority 999, package 0.4.99 will not be installed to satisfy the pin. To make a package "downgradable", to satisfy the pin, it needs possess a priority greater than 1000.
 
A pin can be specified on a package's version, release or origin.
 
Pinning on a version, as we have seen, supports literal version numbers as well as wildcards to specify several versions at one time.
 
Option release depends on the Release file from an APT repository or from a CD. This option may be of no use at all if you're using package repositories that don't provide this file. You may see the contents of the Release files that you have on /var/lib/apt/lists/. The parameters for a release are: a (archive), c (components), v (version), o (origin) and l (label).
 
An example:
 
 
<pre><nowiki>
 
<pre><nowiki>
  Package: *
+
apt-cache policy firefox-3.5
  Pin: release v=2.2*,a=stable,c=main,o=Debian,l=Debian
+
  Pin-Priority: 1001
+
</nowiki></pre>
+
In this example, we chose version 2.2* of Debian (which can be 2.2r2, 2.2r3 -- this accomodates "point releases" that typically include security fixes and other very important updates), the stable repository, section main (as opposed to contrib or non-free) and origin and label Debian. Origin (o=) defines who produced that Release file, the label (l=) defines the name of the distribution: Debian for Debian itself and Progeny for Progeny, for example. A sample Release file:
+
<pre><nowiki>
+
  $ cat /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_warty_main_binary-i386_Packages
+
  Archive: stable
+
  Version: 2.2r3
+
  Component: main
+
  Origin: Ubuntu
+
  Label: Debian
+
  Architecture: i386
+
</nowiki></pre>
+
To see which source you have and which priorities they are assigned you can run <code><nowiki>apt-cache policy</nowiki></code>
+
You can even find out which versions of a package you could install. Example for the "nautilus" package: <code><nowiki>apt-cache policy nautilus</nowiki></code>
+
=== An example /etc/apt/sources.list ===
+
<pre><nowiki>
+
  deb http://archive.ubuntu.com/ubuntu breezy universe
+
  deb-src http://archive.ubuntu.com/ubuntu breezy universe
+
 
+
  deb http://security.ubuntu.com/ubuntu breezy-security main restricted
+
  deb-src http://security.ubuntu.com/ubuntu breezy-security main restricted
+
 
+
  deb http://archive.ubuntu.com/ubuntu/ hoary main restricted universe multiverse
+
  # deb-src http://archive.ubuntu.com/ubuntu/ hoary main restricted universe
+
 
+
  deb http://security.ubuntu.com/ubuntu/ hoary-security main restricted
+
  # deb-src http://security.ubuntu.com/ubuntu/ hoary-security main restricted
+
 
+
  #Mono
+
  deb http://www.getsweaaa.com/~tseng/ubuntu/debs ./
+
  deb-src http://www.getsweaaa.com/~tseng/ubuntu/debs ./
+
 
</nowiki></pre>
 
</nowiki></pre>
=== Links ===
+
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:
 
These documents were used as a foundation for this page, and might give you more background information:
 
* For Basic apt-get usage and instructions see [[UbuntuHelp:AptGetHowTo|AptGetHowTo]]
 
* For Basic apt-get usage and instructions see [[UbuntuHelp:AptGetHowTo|AptGetHowTo]]
* [http://www.debian.org/doc/manuals/apt-howto/ch-apt-get.en.html The official debian documentation]
+
* [http://www.debian.org/doc/manuals/apt-howto/ch-apt-get.en.html The official Debian documentation]
* [http://jaqque.sbih.org/kplug/apt-pinning.html John H. Robinson, IV, Apt-pinning for beginners]
+
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconNote.png Note:
+
Most of this document is taken from [http://www.debian.org/doc/manuals/apt-howto/ch-apt-get.en.html The official debian documentation]
+
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
+
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2010年5月19日 (三) 23:53的最新版本

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: