Summary
How can I make apt-get prefer local repository packages instead of downloading again the same package version from official repositories? The local repository is signed and trusted. We've already tried apt preferences priority.
Original question was : "How to assign highest priority to local repository without using sources.list file"
I have setup a local repository with packages I downloaded. I use it to avoid downloading the same packages over the Internet, when I need to reinstall my Ubuntu. It is a basic repository, created with apt-ftparchive packages . > Packages
. I made this a trusted repository to avoid "unauthenticated repository" warning. (When you have a untrusted repository, apt
or synaptic
try to download the same packages over the Internet, 'cause it is trusted).
I have been using this local repository for at least 1 years. But I have to always put my local repository line at the top of the sources.list
file to use this. But this is annoying, since I must open a terminal and do some typing on it every time I reinstall Ubuntu, though there is a better tool software-properties-gtk
. I cannot use this tool since it place the source line at the end of `sources.list.
And the real problem is that, the apt
or synaptic
always download a package from the source which is mentioned earlier, without inspecting whether the packages are already available in the local repository. So, I have no choice but to place the local source at the top of sources.list
doing terminal (I actually don't hate terminal, but I need a solution) .
I have tried this method. But this does not help me.
My preference file is this in /etc/apt/preferences.d/local-pin-900
Package: *
Pin: release o=Local,n=ubuntu-local
Pin-Priority: 900
My release file is this
Origin: Local
Label: Local-Ubuntu
Description: Local Ubuntu Repository
Codename: ubuntu-local
MD5Sum:
ed43222856d18f389c637ac3d7dd6f85 1043412 Packages
d41d8cd98f00b204e9800998ecf8427e 0 Sources
When I enable the apt-preference, the apt-cache policy
correctly shows the preference, e.g. It shows the local repository has the highest priority.
But when I do this sudo apt-get install <package-name>
, apt
tries to download it from Internet. But when I place my local-repo at the top, it installs from local repository.
So, My question is -> 'Is it possible to force apt to use local repository when the package is available in local repository, without explicitly placing "the local source" at the top of my repository list (e.g sources.list file) ?'
Edit: output of apt-cache policy $package_name
is as follows
nautilus-wipe: Installed: (none) Candidate: 0.1.1-2 Version table: 0.1.1-2 0 500 http://archive.ubuntu.com/ubuntu/ precise/universe i386 Packages 900 file:/media/Main/Linux-Software/Ubuntu/Precise/ Packages
It is showing that my local repository has higher preference, though it is not the one which comes first in sources.list
file.
Here is the output of apt-get install nautilus-wipe
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: nautilus-wipe 0 upgraded, 1 newly installed, 0 to remove and 131 not upgraded. Need to get 30.7 kB of archives. After this operation, 150 kB of additional disk space will be used. 'http://archive.ubuntu.com/ubuntu/pool/universe/n/nautilus-wipe/nautilus-wipe_0.1.1-2_i386.deb' nautilus-wipe_0.1.1-2_i386.deb 30730 MD5Sum:7d497b8dfcefe1c0b51a45f3b0466994
It is still trying to get the file from Internet, though I think it should be happy with the local one.
Result of using "" or localhost as mediageek suggested
Using localhost has no effect. but "" has but was not different than my method
Package: *
Pin: origin ""
Pin-Priority: 1001
I have used them before posting the question. But again i tried this (for surity). The same result. apt-cache policy
showing that my local repository has indeed the highest priority. but when i tried to install it is saying "Need to get XXX/XXX KB of archive".
The short answer:
Here is the file
/etc/apt/preferences
, whichapt-get
use to decide, which version it's have to select if there are many versions of a single packge. With this, any package that comes from the local repository, will take precedence over the other packages.This won't control the version, but the source preference if both packages has the same version. If you need to assign highest priority for the same package version in your local repo, list them at the top to the
/etc/apt/sources.list
file>Answer to the original question:
There is no way to assign highest priority to local repository without using
sources.list
file. you must put them in top of "sources.list" if you want to assign highest priority to your local repo.Summary answer to this question:
Using the
/etc/apt/sources.list
file, You need to put your local repository line at the top of this file. like the below one.And yes, "apt_preference" has nothing to do with selecting instances of the packages with same version. The point here is, you can't use
/etc/apt/preference
file to force to select/use a.deb
file from your local repository by assigning highest priority to your local one. That file(preference) is used to select an specific version, not a specific instance (.deb file) of the same version. For the latter case, you need to use/etc/apt/sources.list
file with above mentioned method.Explanation:
Seems we all misunderstood the
apt_preference
purpose , the apt_preference manual describes this in the first 3 paragraph!!And the very important one is in third paragraph
Those Italics were made by mine
Let's see this with an example:
I have precise's version of
compiz-fusion-plugins-extra
, but I disabled that for demonstrationHere is the file
/etc/apt/preferences
, whichapt-get
use to decide, which version it's have to select if there are many versions of a single packge. (In this example,compiz-fusion-plugins-extra
has several versions.This file says
apt-get
to install from local repository for all packages which have several versions exists in different repository.In other words, if I have package
xapps
with version1.0
in my local repository, and this same packagexapps
exists in Precise's repository with higher version, say2.0
,apt-get
will prefer the version from local repository, i.e version1.0
.Here is my
/etc/apt/sources.list
fileAlthough, I have listed the precise's repository earlier in the file, it does not cause
apt-get
to select package from that repository. As described in the manualSo, the output of the command
apt-cache policy compiz-fusion-plugins-extra
was as expected as belowHere, the candidate version is
0.9.5.94-0ubuntu1
, (which is in the local repository), not0.9.7.0~bzr9-0ubuntu6 0
, which is in precises' repository. although the precises' one was listed first in thesources.list
file.An example run of
apt-get
trying to installcompiz-fusion-plugins-extra
after setting highest priority to local repository.Strange!!!, It is trying to downgrade the already installed compiz packages of precise to resolve dependencies (matching with Oneiric's one) with newly selected
compiz-fusion-plugins-extra
!!!.Which is more dangerous is , it is trying to remove graphics driver packages (xserver-xorg-....) to avoid conflict with new compizes.
(Probably, If I also had them in my local repository, they may safely want to downgrade. But as those packages are usually installed, i did not download them, so aren't in local repo, hence this result).
Conclusion: So, using
/etc/apt/preferences
is only recommended to use with local repository, if you have complete repository in local system.What if several instances (.deb file) of the same version exists in many repository.
Which is described by the
apt_preference
manualAn example of use cases for
/etc/apt/preferences
file:An example of forcing
apt-get
to select version available from a custom repo, instead of Ubuntu's standard one may be the "Linux Mint" distribution. They use this custompreference
file.This effectively causes them, to provide packages when they have those in their repositories. But if they don't have them, they use Ubuntu's standard repository.
An Example running
apt-get
after setting highest priority to local repositoryI just wanted to install
kubuntu-desktop
package over Ubuntu to test KDE. (I forgot that, i have set a preference using/etc/apt/preference
file). I had an iso of the kubuntu-12.04-alternate-installer, so i thought I can use that.(after properly setting the iso as repository source), I ran
sudo apt-get install kubuntu-desktop
, then surprised by seeing the output below.I was surprised by the result. suddenly i remember that, I have set a preference (for writing this answer) in
/etc/apt/preference
to set highest priority to my local repository.so, I ran this:
apt-cache policy kubuntu-desktop
, the output was as below:In this output, we see that both the "cdrom" and "precise main repository" has version number 1.254, while the local repository has version 1.222.1kde47~ppa2, which is lower version. Although, they are placed before the local ones in sources.list file, local packages got precedence.
To explicitly see that
apt-get
is indeed trying to install from local one, I ransynaptic
and got this, which is showing that, the Apt system consider 1.222.1kde47~ppa2 as the candidate version to install.Also
apt-cache policy kubuntu-desktop
showing the same thingsTo solve this, I removed the
/etc/apt/preference
file bysudo rm /etc/apt/preference
.Then ran again this again
apt-cache policy kubuntu-desktop
. only seeing this expected output.Also ran this again.
sudo apt-get install kubuntu-desktop
to see the output below:You can check the full result here
Then I pretty much sure about the Explanation portion.
Reference 1 : The apt_preference manual
Reference 2: How to Keep a specific version of packages installed