42

How do I limit the updates that are installed to those from a specific set of repositories? Is this at all possible?

3
  • Do you want to be able to specify repo during runtime, or should be it be more a static thing? The two answers below assume the latter option.
    – tshepang
    Feb 21, 2011 at 12:50
  • Ideally it would be during runtime. The static option is sufficient though. Feb 22, 2011 at 8:11
  • 2
    You heading and the actual help you are requesting are different.
    – sundar
    Apr 27, 2016 at 15:08

6 Answers 6

42

You can specify a release with -t option. As an example, I have added the following repository to /etc/apt/sources.list to install Iceweasel latest release:

deb http://mozilla.debian.net/ squeeze-backports iceweasel-release

As you know there is a same package iceweasel in the official Debian repository. If I want install Iceweasel from this specific release I run:

apt-get install -t squeeze-backports iceweasel

from apt-get manual page:

-t, --target-release, --default-release
           This option controls the default input to the policy engine, it creates a default pin at priority 990 using the specified
           release string. This overrides the general settings in /etc/apt/preferences. Specifically pinned packages are not affected by
           the value of this option. In short, this option lets you have simple control over which distribution packages will be retrieved
           from. Some common examples might be -t '2.1*', -t unstable or -t sid. Configuration Item: APT::Default-Release; see also the
           apt_preferences(5) manual page.

I think this is a better solution.

UPDATE: As @SuB mentioned in the comment, "-t specifies release not repository name. There is no repository name in Ubuntu (unlike RedHat based linux such as RHEL,Fedora,CentOS, ...)".

3
  • 4
    As you see in the apt-get manual, -t specify release not repository name. There is no repository name in Ubuntu (unlike RedHat based linux such as RHEL,Fedora,CentOS, ...)
    – SuB
    Sep 20, 2013 at 17:31
  • 1
    @SuB Yes, you're right! I confused repository name with release!
    – cartoonist
    Sep 21, 2013 at 15:19
  • 1
    -t xenial works for a single package. but all it's dependencies will still be fetched from higher packages
    – Anwar
    Aug 19, 2016 at 9:16
36

Use 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. — help.ubuntu.com

You can disable automatic updates from certain repositories without entirely removing them via apt policies:

To disable automatic updates from repository repo, add a file
/etc/apt/preferences.d/repo with the following content:

Package: *
Pin: release n=repo
Pin-Priority: 50

Which will give all packages from this repository a lower priority than already installed packages (which have 100).

For more information man apt_preferences or check the Ubuntu Community Wiki.

4
  • 3
    It’s a shame the only apt_preferences answer is the last... Jan 25, 2014 at 9:22
  • how to find out which version is from which repo?
    – Max N
    Jun 15, 2016 at 12:13
  • 2
    @MaxN you would usually find that information by running apt-cache policy package-name
    – Anwar
    Aug 21, 2016 at 6:15
  • This will not force a repository for not being considered while update. because release n=repo will not cache anyone
    – Anwar
    Aug 21, 2016 at 10:06
14

Short Answer

You need to pin the repositories you don't want to install from with a priority less than 100. Which means (from apt_preference man page)

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

And to select a repository for pinning, you'd use fields from repositories' Release file. Such as archive, label, release, version etc. By specifying the values of these fields, you can precisely select a repository and assign your preferred priority to it. Check the apt_preference page for more details.


Long Answer

Before proceeding, we need to know some important thing about pinning. Those includes

  1. Fields of Release files and It's mapping to apt-cache policy output

  2. Format of apt preference files

  3. Using Release files fields to set priority

1. Fields of Release file and apt-cache policy output

From Debian Wiki article

  • Description
  • Label
  • Origin
  • Version
  • Suite
  • Codename
  • Components
  • Architectures

You would see output from apt-cache policy like these

 500 http://mirrors.ircam.fr/pub/ubuntu/archive xenial/main amd64 Packages
 release v=16.04,o=Ubuntu,a=xenial,n=xenial,l=Ubuntu,c=main,b=amd64

The values in these lines comes from Release files.

  • Description sets the description for a repository. This is not shown in apt-cache policy output

  • Label it is the label of the repository. Many repositories have empty labels. It's shown in l=<label> in the output.

  • Origin this tells about the origin of the repository. Official Ubuntu repository has Ubuntu as the value. Shown as o= in the output

  • Version is the version of a distribution. It's 16.04 for Xenial. Shown as v= in the output

  • Suite is same as Archive. From debian wiki it's is The name of the distribution of Debian the packages in this directory belong to (or are designed for), i.e. stable, testing or unstable.. For Ubuntu, these are release-updates, release-security etc. For example, xenial-updates, xenial-security. It's shown in the output as a=xenial, a=xenial-security. PPAs use just the release name for this, that's why it won't help much in Pinning.

  • Component tells about the licencing thing. It's main, multiverse, restricted, universe in Ubuntu. In the output it's shown as c=main or c=restricted etc. Most PPAs use main for this field, thus it doesn't help in pinning much either.

  • Architecture is about the OS architecture. Shown as b=i386 or b=amd64 in the output

  • Codename is the release name of the distribution. For 16.04 it is xenial. For 14.04 it is trusty. Shown in apt-cache policy output as n=xenial or n=trusty. It's same for all repositories for a single distribution usually. That's why it doesn't help in pinning much.

The other line in apt-cache policy output starting with origin tells the Internet origin of the repository. It also can be used in pinning. But should not be mixed with Release files Origin field. Those are different.

We'll use these values to pin a repository.

So, how do we use pinning1 to restrict repository?

There are several ways to control pinning and only a small-subset is effective for Ubuntu. A details explanation is beyond the scope of the answer though. Please refer to apt_preference man-page for this.

2. Pin file format

Pin or apt preference files reside in /etc/apt/preferences.d folder. Each pinning contain three lines.

  • First line starts with Package: and a comma-seperated package names follow. Regular expressions and globs are allowed

  • Second line starts with Pin: and it is used to target a set of packages.

    If we want to pin packages from xenial higher than xenial-updates, we'll use release a=xenial.

    If we want to pin version 5.0, we'll use version 5.0 here. Glob pattens are allowed.

    Or if we want to pin packages from origin http://archive.ubuntu.com, we'll use origin "archive.ubuntu.com". Note, we don't write http:// protocol there.

  • Third line starts with Pin-Priority: and it's value is a number. Which signifies the priority of the targeted items above.

3. Using Release files fields to set priority

Here is an example

Package: *
Pin: release a=xenial
Pin-Priority: 1001

In this example, packages from xenial archives are given higher priority than xenial-updates and xenial-security.

After pinning, running an apt-cache policy nautilus shows that it indeed has given higher priority to a lower version from xenial archive over a higher-versioned from xenial-updates archive. Notice the Candidate: line.

nautilus:
  Installed: 1:3.18.5-0ubuntu1~xenial1
  Candidate: 1:3.18.4.is.3.14.3-0ubuntu4
  Version table:
 *** 1:3.18.5-0ubuntu1~xenial1 100
        100 /var/lib/dpkg/status
     1:3.18.4.is.3.14.3-0ubuntu5 500
        500 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
     1:3.18.4.is.3.14.3-0ubuntu4 1001
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

But, If we want to give priority over PPA provided packages too, this won't work. Because PPAs use same archive name xenial by default. So, assigning a priority to a=xenial will also apply to those packages. For example (after enabled PPA),

13:31 $ apt-cache policy nautilus
nautilus:
  Installed: 1:3.18.5-0ubuntu1~xenial1
  Candidate: 1:3.18.5-0ubuntu1~xenial1
  Version table:
 *** 1:3.18.5-0ubuntu1~xenial1 1001
        500 http://ppa.launchpad.net/budgie-remix/ppa/ubuntu xenial/main amd64 Packages
        500 http://ppa.launchpad.net/gnome3-team/gnome3/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status
     1:3.18.4.is.3.14.3-0ubuntu5 500
        500 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
     1:3.18.4.is.3.14.3-0ubuntu4 1001
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

Now the candidate version is from a PPA. Both packages from xenial archive of official Ubuntu repo and the PPA have same priority 1001, because both of them use same value for Archive in Release file. To successfully pin, we need to combine more fields in Pin file.


Some examples

Pin a PPA repository

To pin packages from a repository, we need to target it using the information found from apt-cache policy command. We just saw that a=xenial won't help pin-pointing a repository. We need to use multiple fields together using comma in a preference file to precisely target a repository.

For example, to prevent all packages from http://ppa.launchpad.net/oibaf/graphics-drivers/ ppa, we can use

Package: *
Pin: release n=xenial,o=LP-PPA-oibaf-graphics-drivers
Pin-Priority: 10

Here we are using the codename value as well as Origin value of the PPA. (Though codename value is not required here actually). Sometimes repository may miss these value. In those cases, some other techniques should be used. The output of apt-cache policy libgl1-mesa-glx says that it works. It lowered the priority of all packages of this PPA.

libgl1-mesa-glx:
  Installed: 12.1~git1608200730.16ef7a~gd~x
  Candidate: 12.1~git1608200730.16ef7a~gd~x
  Version table:
 *** 12.1~git1608200730.16ef7a~gd~x 100
        -10 http://ppa.launchpad.net/oibaf/graphics-drivers/ubuntu xenial/main amd64 Packages
        100 /var/lib/dpkg/status
     11.2.0-1ubuntu2.1 500
        500 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages
     11.2.0-1ubuntu2 500
        500 http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages

Ignore the fact that it is Candidate. This happended, because It is already installed in my system. Check the priority at the right

Pin a repository when release info is missing

If we want to pin a repository whose release information is missing, like this one http://download.opensuse.org/repositories/home:/sarimkhan/xUbuntu_14.04, we must use other method. Since, no other repository is using that origin, we can safely use origin to pin this repository.

Package: *
Pin: origin download.opensuse.org
Pin-Priority: 10

Note 1: This origin is the Internet origin, not the one which specifies Vendor in the Release file.

Note 2: Pin-Priority number has special meaning. Check apt_preference manual page for details.

3
  • Pinning is completely useless if the package is newer in the repo you're trying to avoid. That is, most of the time.
    – bviktor
    Nov 26, 2019 at 10:08
  • @bviktor How about installing with sudo apt-get install <package name>=<version> source
    – Madacol
    Feb 17, 2020 at 21:23
  • Man page is man apt_preferences with S at the end!
    – Zeke Fast
    Jul 23, 2020 at 22:39
7

A gui based alternative would be to open software centre and select edit > software sources...

Software Sources with Ubuntu software tab selected

Software Sources with other software tab selected

all you need to do is un-tick the repositories you don't want updates from.

Hope this helps

5

Obvious choice is to modify /etc/apt/sources.list and comment out all other repositories, and then run

apt-get update && apt-get upgrade && apt-get autoclean

And then remove comments from sources.list. Maybe not the best way, but at least apt-get man pages do not specify any way to do that.

On related note, for example Ubuntu distribution upgrade process disables all 3rd party repositories during upgrade (and do not just run some option to exclude those temporarily).

2

One other GUI option is to just choose the origin in Synaptic package manager.

  1. Search for the package name you want to install
  2. Click the Origin button
  3. Choose the repository you want to install from
  4. Choose the packages
  5. Apply

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .