I recently had to test some of my locally generated MariaDB debian packages. So, created a local repository of generated packages and added it to sources.list file. However, since these packages required some other packages stored on a mirror, I had to add the mirror to the sources.list file as well. Since, this mirror also contained the packages that I intended to test, now when I try to install the packages, APT would always pick/prefer the ones stored on the mirror. How to solve this? How to make APT prefer the local packages instead? Lets start by taking a peek into the sources.list file:
$cat /etc/apt/sources.list .. # remote repo deb http://mirror.jmu.edu/pub/mariadb/repo/5.5/ubuntu precise main # local repo deb file:///home/nirbhay/project/repo/maria/testing/debian/5.5/debs binary/ .. $ sudo apt-cache policy mariadb-galera-server mariadb-galera-server: Installed: (none) Candidate: 5.5.37+maria-1~precise Version table: 5.5.37+maria-1~precise 0 500 file:/home/nirbhay/project/repo/maria/testing/debian/5.5/debs/ binary/ Packages 500 http://mirror.jmu.edu/pub/mariadb/repo/5.5/ubuntu/ precise/main i386 Packages
The following tips can help you fix this problem :
If remote and local packages have the same version (as in my case), place one that you want to be preferred higher in sources.list file.
APT prefers authenticated repository over unauthenticated. So, as against the above case, even if the local repository is placed over the remote, APT will prefer remote one if its authenticated and the local repository is not. In that case, –allow-unauthenticated can be used to make local packages take precedence.
In case local and remote packages have different versions, APT would always prefer the package with higher version. However, this rule can be eased by apt-pinning, where a higher priority is assigned to a particular repository. For example, local repository can be pinned with higher priority (or precedence in APT’s context) by adding a file under /etc/apt/preferences.d with .pref extension and the following content :
Package: * Pin: origin "" Pin-Priority: 1000
This has been explained really well in this thread.
Lastly, do not forget to run “apt-get update” for changes to take effect.