apt-get install specific version with non-candidate dependencies
<p>I want to build a debian package, which has a <code>Build-Depends</code> field and in it there is specific version of a library. I used to do <code>mk-build-deps -i</code> and then <code>dpkg-builpackage</code>, but I run into troubles when I specify specific version of a build dependency.</p>
<p>I have build a minimal repeatable example:</p>
<pre><code>docker run -it --rm debian:jessie bash
apt-get update &amp;&amp; apt-get install -y devscripts
mkdir -p /foo/debian
cd foo/
echo &quot;foo (1.0.0) UNRELEASED; urgency=medium

  * Initial release. (Closes: #XXXXXX)

 -- anon  Wed, 20 Apr 2016 13:48:31 +0200&quot; &gt; debian/changelog

echo &quot;Source: foo
Build-Depends:
 libc6-dev (=2.19-18+deb8u3)

Package: foo
Architecture: all&quot; &gt; debian/control

dpkg -l libc6     # returns 2.19-18+deb8u4
dpkg -l libc6-dev # returns 2.19-18+deb8u4

mk-build-deps -i # this fails to install the libc6-dev dependency, but actually the script returns 0 as return code

dpkg -l libc6     # returns 2.19-18+deb8u4
dpkg -l libc6-dev # returns 2.19-18+deb8u4 although it should return  2.19-18+deb8u3
apt-get install -y libc6-dev=2.19-18+deb8u3 # fails
apt-get install -y libc6-dev=2.19-18+deb8u3 libc6=2.19-18+deb8u3 libc-dev-bin=2.19-18+deb8u3 # this finally installs desired versions
</code></pre>
<p>But this is very manual work. So really, apt-get install cannot install packages with dependencies which are not candidates? Is there other tool I can use or I have to do this manually for every package?</p>
<p>Thanks</p>
<hr />
<p>Updated with outputs:</p>
<pre><code>root@4f32a97063a2:/foo# dpkg -l libc6     # returns 2.19-18+deb8u4
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                     Architecture                Description
+++-=============================================-===========================-===========================-================================================================================================
ii  libc6:amd64                                   2.19-18+deb8u4              amd64                       GNU C Library: Shared libraries



root@4f32a97063a2:/foo# dpkg -l libc6-dev # returns 2.19-18+deb8u4
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                     Architecture                Description
+++-=============================================-===========================-===========================-================================================================================================
ii  libc6-dev:amd64                               2.19-18+deb8u4              amd64                       GNU C Library: Development Libraries and Header Files



root@4f32a97063a2:/foo# mk-build-deps -i # this fails to install the libc6-dev depedency, but actually the script returns 0 as return code
parsechangelog/debian: warning:     debian/changelog(l5): badly formatted trailer line
LINE:  -- anon  Wed, 20 Apr 2016 13:48:31 +0200
parsechangelog/debian: warning:     debian/changelog(l5): found eof where expected more change data or trailer
dh_testdir
dh_testroot
dh_prep
dh_testdir
dh_testroot
dh_install
dh_installdocs
dh_installchangelogs
dh_compress
dh_fixperms
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb
dpkg-deb: building package `foo-build-deps' in `../foo-build-deps_1.0.0_all.deb'.

The package has been created.
Attention, the package has been created in the current directory,
not in &quot;..&quot; as indicated by the message above!
Selecting previously unselected package foo-build-deps.
(Reading database ... 22567 files and directories currently installed.)
Preparing to unpack foo-build-deps_1.0.0_all.deb ...
Unpacking foo-build-deps (1.0.0) ...
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages will be REMOVED:
  foo-build-deps
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 2048 B disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 22571 files and directories currently installed.)
Removing foo-build-deps (1.0.0) ...


root@4f32a97063a2:/foo# dpkg -l libc6     # returns 2.19-18+deb8u4
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                     Architecture                Description
+++-=============================================-===========================-===========================-================================================================================================
ii  libc6:amd64                                   2.19-18+deb8u4              amd64                       GNU C Library: Shared libraries
root@4f32a97063a2:/foo# dpkg -l libc6-dev # returns 2.19-18+deb8u4 although it should return  2.19-18+deb8u3
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                     Architecture                Description
+++-=============================================-===========================-===========================-================================================================================================
ii  libc6-dev:amd64                               2.19-18+deb8u4              amd64                       GNU C Library: Development Libraries and Header Files



root@4f32a97063a2:/foo# apt-get install -y libc6-dev=2.19-18+deb8u3 # fails
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libc6-dev : Depends: libc6 (= 2.19-18+deb8u3) but 2.19-18+deb8u4 is to be installed
             Depends: libc-dev-bin (= 2.19-18+deb8u3) but 2.19-18+deb8u4 is to be installed
E: Unable to correct problems, you have held broken packages.



root@4f32a97063a2:/foo# apt-get install -y libc6-dev=2.19-18+deb8u3 libc6=2.19-18+deb8u3 libc-dev-bin=2.19-18+deb8u3 # this finally installs desired versions
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  glibc-doc locales
The following packages will be DOWNGRADED:
  libc-dev-bin libc6 libc6-dev
0 upgraded, 0 newly installed, 3 downgraded, 0 to remove and 0 not upgraded.
Need to get 6906 kB of archives.
After this operation, 2048 B of additional disk space will be used.
E: There are problems and -y was used without --force-yes
root@4f32a97063a2:/foo# apt-get install  libc6-dev=2.19-18+deb8u3 libc6=2.19-18+deb8u3 libc-dev-bin=2.19-18+deb8u3 # this finally installs desired versions
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  glibc-doc locales
The following packages will be DOWNGRADED:
  libc-dev-bin libc6 libc6-dev
0 upgraded, 0 newly installed, 3 downgraded, 0 to remove and 0 not upgraded.
Need to get 6906 kB of archives.
After this operation, 2048 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://security.debian.org/ jessie/updates/main libc6-dev amd64 2.19-18+deb8u3 [2003 kB]
Get:2 http://security.debian.org/ jessie/updates/main libc-dev-bin amd64 2.19-18+deb8u3 [237 kB]
Get:3 http://security.debian.org/ jessie/updates/main libc6 amd64 2.19-18+deb8u3 [4666 kB]
Fetched 6906 kB in 0s (14.8 MB/s)
debconf: delaying package configuration, since apt-utils is not installed
dpkg: warning: downgrading libc6-dev:amd64 from 2.19-18+deb8u4 to 2.19-18+deb8u3
(Reading database ... 22567 files and directories currently installed.)
Preparing to unpack .../libc6-dev_2.19-18+deb8u3_amd64.deb ...
Unpacking libc6-dev:amd64 (2.19-18+deb8u3) over (2.19-18+deb8u4) ...
dpkg: warning: downgrading libc-dev-bin from 2.19-18+deb8u4 to 2.19-18+deb8u3
Preparing to unpack .../libc-dev-bin_2.19-18+deb8u3_amd64.deb ...
Unpacking libc-dev-bin (2.19-18+deb8u3) over (2.19-18+deb8u4) ...
dpkg: warning: downgrading libc6:amd64 from 2.19-18+deb8u4 to 2.19-18+deb8u3
Preparing to unpack .../libc6_2.19-18+deb8u3_amd64.deb ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Unpacking libc6:amd64 (2.19-18+deb8u3) over (2.19-18+deb8u4) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libc6:amd64 (2.19-18+deb8u3) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Setting up libc-dev-bin (2.19-18+deb8u3) ...
Setting up libc6-dev:amd64 (2.19-18+deb8u3) ...
Processing triggers for libc-bin (2.19-18+deb8u4) ...
</code></pre>