个人工具

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

来自Ubuntu中文

跳转至: 导航, 搜索
 
(未显示同一用户的4个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/PinningHowto}}
 
{{From|https://help.ubuntu.com/community/PinningHowto}}
 
{{Languages|UbuntuHelp:PinningHowto}}
 
{{Languages|UbuntuHelp:PinningHowto}}
=== Introduction to Pinning Packages ===
+
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.
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.
+
== Introduction to Pinning ==
This guide will be when you need or want to install an older version of a program on a newer version of Ubuntu.
+
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.
This is important if you are running development versions of Ubuntu or any software that maybe in testing or unstable release -- example Firefox-3.0 in Hardy, it isn't stable so if a patch or new version causes something to break you can install the old version and pin the package so Apt or Synaptic doesn't keep wanting you to upgrade to the broken 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 [[UbuntuHelp:UbuntuBackports|UbuntuBackports]] before doing this.
First way to pin a package is in Synaptic:  
+
=== 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:
 
<pre><nowiki>
 
<pre><nowiki>
Open Synaptic
+
APT::Default-Release "hardy";
Click on Search and type the package name in the Search box
+
Highlight the version you want to pin '''Make sure its the version that is not broken'''
+
Click on the menu item Package than click on lock version
+
Close Synaptic
+
 
</nowiki></pre>
 
</nowiki></pre>
Second way is to pin it with Apt/Dpkg:
+
The second file is:
 +
/etc/apt/sources.list
 +
An example configuration is as follows:
 
<pre><nowiki>
 
<pre><nowiki>
Open a terminal
+
# official ubuntu sites
sudo -s and hit enter
+
deb http://archive.ubuntu.com/ubuntu hardy main restricted universe multiverse
Enter your password for sudo
+
deb http://archive.ubuntu.com/ubuntu intrepid main restricted universe multiverse
echo libxfont1 hold | dpkg --set-selections  '''Replace libfont1 with the package you want to pin'''
+
Now run sudo apt-get update and than sudo apt-get upgrade
+
 
</nowiki></pre>
 
</nowiki></pre>
This part will be removing the pin that you used to pin the file. This should be when the package is fixed or removed.
+
In this example, we're pulling from hardy and intrepid (the current development version of Ubuntu).
You can check what the next version of the package is by using apt-cache policy packagename 
+
The next file involved is:
To remove the pin in Synaptic:
+
/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:
 
<pre><nowiki>
 
<pre><nowiki>
Open Synaptic
+
Package: firefox-3.0
Search packagename
+
Pin: release a=hardy
Click on package
+
Pin-Priority: -10
Click on menu item packages
+
 
Now click unlock
+
Package: firefox-3.0
Close Synaptic
+
Pin: release a=intrepid
 +
Pin-Priority: 900
 
</nowiki></pre>
 
</nowiki></pre>
To remove pin from Apt/Dpkg:
+
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>
Open a terminal
+
deb-src http://archive.ubuntu.com/ubuntu intrepid main restricted universe multiverse
sudo -s and hit enter
+
Enter your password for sudo
+
echo libxfont1 install | dpkg --set-selections '''Replace libfont1 with the package you want to pin'''
+
Now run sudo apt-get update and than sudo apt-get upgrade
+
 
</nowiki></pre>
 
</nowiki></pre>
 +
Then you'll need to update your repos:
 +
<pre><nowiki>
 +
sudo apt-get update
 +
</nowiki></pre>
 +
Now we need to install some packages so we can build the desired software in intrepid:
 +
<pre><nowiki>
 +
sudo apt-get build-dep firefox-3.0
 +
</nowiki></pre>
 +
Now we can do the following to get the package built from intrepid on our hardy machine:
 +
<pre><nowiki>
 +
sudo apt-get -b source -t intrepid firefox-3.0
 +
</nowiki></pre>
 +
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>
 +
echo libxfont1 hold | 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
 +
== 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
 +
*<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'''  
 
'''NOTE'''  
 
At the time of the making this Wiki there is not a known way to Pin a package with Update Manager.
 
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.
 
Pinning should never be used for installing Debian binary packages on Ubuntu.
 
Ubuntu strongly recommends against using Debian binary packages on Ubuntu,  
 
Ubuntu strongly recommends against using Debian binary packages on Ubuntu,  
=== Links ===
+
== 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>
 +
      Package: *
 +
      Pin: release o=LP-PPA-ubuntu-mozilla-daily
 +
      Pin-Priority: 400
 +
</nowiki></pre>
 +
Use the following commands, before and after, to check that the Pin-Priority has been updated.
 +
<pre><nowiki>
 +
apt-cache policy
 +
</nowiki></pre>
 +
<pre><nowiki>
 +
apt-cache policy firefox-3.5
 +
</nowiki></pre>
 +
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]
[[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: