How do I cherry pick packages from a PPA?

Is there a way to cherry pick packages from a ppa repository you add? That is, to exclude some from updating while including others?

For example, I want just the chromium-browser package from this repository but not the others. So I don't want my sudo apt-get upgrade to have that ppa's other (besides chromium-browser) packages install over my existing ones, just that one.

I realize this is a license to shoot myself in the foot if I misread dependencies and exclude ones that are needed to ones that I included, but I know for a fact in this case that the other packages are not dependencies for that one.

Is this at all possible? Maybe there is some whitelist/blacklist file or something?


Solution 1:

Found one way to do it.

The trick is using two pinning clauses. The first to disallow ALL packages from the PPA and the second to select the ones you want.

So for the example above, I first add the ppa as usual:

$ sudo add-apt-repository ppa:webapps/preview
...
$ sudo apt-get update
...

Now if i run apt-cache policy, it will show me that there's a newer version of chromium-browser available and that it will install with an upgrade because it's in the same priority (500) as my current chromium-browser.

$ sudo apt-cache policy chromium-browser
chromium-browser:
  Installed: 18.0.1025.168~r134367-0ubuntu0.12.04.1
  Candidate: 20.0.1132.47~r144678-0precise1+webapps3
  Version table:
     20.0.1132.47~r144678-0precise1+webapps3 0
        500 http://ppa.launchpad.net/webapps/preview/ubuntu/ precise/main amd64 Packages
 *** 18.0.1025.168~r134367-0ubuntu0.12.04.1 0
        500 http://us.archive.ubuntu.com/ubuntu/ precise-updates/universe amd64 Packages
        500 http://security.ubuntu.com/ubuntu/ precise-security/universe amd64 Packages
        500 http://ppa.launchpad.net/chromium-daily/beta/ubuntu/ precise/main amd64 Packages
        100 /var/lib/dpkg/status
     18.0.1025.151~r130497-0ubuntu1 0
        500 http://us.archive.ubuntu.com/ubuntu/ precise/universe amd64 Packages
E: Unable to parse package file /etc/apt/preferences.d/webapps-preview-pin-400 (1)
$ 

That's great as far as that package but I don't want the others in this ppa (which also have a 500 priority) to install. Right now if I try to upgrade, I'll get more than just the chromium packages I want from that repository:

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages have been kept back:
  bamfdaemon gwibber gwibber-service gwibber-service-facebook gwibber-service-twitter indicator-appmenu libbamf0 libbamf3-0 shotwell
The following packages will be upgraded:
  chromium-browser chromium-browser-l10n chromium-codecs-ffmpeg gwibber-service-identica indicator-messages indicator-status-provider-mc5
  indicator-status-provider-pidgin libindicator-messages-status-provider1
8 upgraded, 0 newly installed, 0 to remove and 9 not upgraded.
Need to get 25.3 MB of archives.
After this operation, 5,034 kB of additional disk space will be used.
Do you want to continue [Y/n]? 

So what I can do is tell apt that I want all the packages in that ppa, webapps-preview in this case, to have a lower priority except the ones with "chromium" in their name. The mechanism for this is pinning a package

I create a file in /etc/apt/preferences.d/ with two clauses. The first one says give all the packages in the webapps-preview ppa a lower priority than the regular one (so that they are not preferred even if they have a higher version number. The second clause partly overrides the first by saying give the packages in that ppa with "chromium" in their name the same priority as other packages so that it will get installed (by it having a higher version number).

$ cat /etc/apt/preferences.d/webapps-preview-pin-400
Package:  *
Pin: release o=LP-PPA-webapps-preview
Pin-Priority: 400


Package:  *chromium*
Pin: release o=LP-PPA-webapps-preview
Pin-Priority: 500

To identify the correct string for "Pin: release" option we can use apt-cache policy again.

$ apt-cache policy
...
500 http://ppa.launchpad.net/webapps/preview/ubuntu/ precise/main i386 Packages
    release v=12.04,o=LP-PPA-webapps-preview,a=precise,n=precise,l=preview,c=main
    origin ppa.launchpad.net
...

For apt versions < 0.8.14 pinned packages have to be specified explicitly as wildcards do not work:

$ cat /etc/apt/preferences.d/webapps-preview-pin-400
Package:  *
Pin: release o=LP-PPA-webapps-preview
Pin-Priority: 400


Package:  chromium-browser chromium-codecs-ffmpeg chromium-browser-l10n chromium-codecs-ffmpeg-extra
Pin: release o=LP-PPA-webapps-preview
Pin-Priority: 500

And now, when i try to upgrade I get only the packages I want from that ppa and not the other ones. All nicely cherry picked for me:

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
  chromium-browser chromium-browser-l10n chromium-codecs-ffmpeg
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 25.1 MB of archives.
After this operation, 5,026 kB of additional disk space will be used.
Do you want to continue [Y/n]?

Solution 2:

You can also select the release you want to install from with the ?origin selector:

Matches package versions whose origin matches the regular expression origin. For instance, “!?origin(debian)” will find any unofficial packages on your system (packages not from the Debian archive).

So, in your specific case you can use:

sudo aptitude install !?origin(LP-PPA-webapps-preview) chromium

Or you can specify the version using <packagename>=<version>:

sudo apt-get install chromium=20.0.1132.47~r144678-0precise1+webapps3

Solution 3:

You can actually "cherry pick" certain packages via Synaptic and it's very easy. It works like this:

  • If you want to do that for certain PPAs only, chose "Origin" (lower left corner) in the Synaptic-window and then choose the PPA you want to change

  • choose all the packages you don't want to upgrade automatically any more.

  • choose menu "Package/Lock Version". All the packages you chose won't be upgraded automatically anymore until you unlock them again.