Ubuntu – Pinning package using own repository and apt-get

aptlocalrepositoryrepository

I created my own repository so I can provide a newer version of a package than the one the Ubuntu repository currently holds. Everything works fine, with the exception that I have to specify the version when installing it:

sudo apt-get install package=1.2.1

If I don't specify the version, then it will install it from Ubuntu's repository.

I tried to put my repository at the top of the sources.list but it doesn't make any difference.

So I'm wondering if there's a flag when building the .deb package that will give priority to my repository at all times? or a flag in the actual repository? I'd prefer not having the user to change their /etc/apt/preferences to set the priority, nor using apt-get -t repo.

I tried to install the Tor browser given this instructions and it does install the latest version from their custom repo. I don't know what they're doing but it does work with only the steps they list.

Best Answer

Solution 1: (using Debian epoch)

Prefix your package version with 1: so that it will be 1:1.2.1 and thus it will always be seen as a higher version. This is very handy if you build your own modified packages and don't want them replaced by Ubuntu upgrades.

When comparing two version numbers, first the epoch of each are compared, then the upstream_version if epoch is equal, and then debian_revision if upstream_version is also equal. epoch is compared numerically.

Source: https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version

Solution 2 (using Pinning)

To set up AptPreferences for a given package add a new file in /etc/apt/preferences.d/.

sudo gedit /etc/apt/preferences.d/my-package-pin

Add add the following lines in that file:

Package: my_package
Pin: release o=Ubuntu
Pin-Priority: -10

I will prevent Ubuntu repository versions to replace the one provided by your local repo.

To check if the package pin version run:

sudo apt-cache policy my_package

Visit https://help.ubuntu.com/community/PinningHowto