I need to use apt-get download to fetch a specific version of a .deb file, but not necessarily the exact version. .deb dependencies are allowed to use expressions such as >=0.3.0 and I would like apt-get download to fetch the same version as the one that would be downloaded using such dependency.

Summing it up, what I want to work is this:

$ apt-get download package='>=0.3.0'

Any idea how I could get that functionality?

  • Why don't you just manually download the package from packages.ubuntu.com?
    – terdon
    Apr 3 '13 at 11:32
  • Because I need to be sure that the package downloaded is the exact same package that would be downloaded when "apt-get install" is executed. I'm incorporating this in a cmake extension script.
    – mikosz
    Apr 3 '13 at 12:51

You could do this by first finding out which version is the newest version that is also greater than or equal to your desired minimum version. Then, you download exactly that version using apt-get download. Here's a script that does this (it's a bit ugly, but you get the idea):


if [ $# -lt 2 ]; then
    echo "Usage: $0 <packagename> <minimum version>"
    exit 1



for version in `apt-cache madison $pkgname | awk -F'|' '{print $2}'`; do
    echo "Considering $version"
    if dpkg --compare-versions $version ge $minversion; then
        echo "- Version is at least $minversion"
        if dpkg --compare-versions $version gt $V; then
            echo "- This is the newest version so far"
            echo "- We already have a newer version"
        echo "- This is older than $minversion"

if [ "$V" = "0" ]; then
    echo "There is no version greater than or equal to $minversion"
    exit 1

echo "Selected version: $V"

echo "Downloading"
apt-get download $pkgname=$V
echo "Done"

You'd have to add error checking in case the package doesn't exist, etc. but this contains the core solution. Also, I've assumed here that you want the newest available package that is at least a certain version. If you would instead like the oldest available package that is at least a certain version, you have to adjust the script to stop searching once it's found something that is at least your desired version.


Since you want exactly what apt-get install would give you, it might be worthwile to run apt-get install in 'download-only mode' using a custom archives directory:

-d, --download-only
  Download only; package files are only retrieved, not unpacked or installed.
  Configuration Item: APT::Get::Download-Only.

How to change the archives directory? This is a configuration option:


  Storage area for retrieved package files. Configuration Item: Dir::Cache::Archives.

Those can be changed temporarily with the --option parameter:

-o, --option
  Set a Configuration Option; This will set an arbitrary configuration option. 
  The syntax is -o Foo::Bar=bar.  -o and --option can be used multiple times 
  to set different options.

To summarize:

apt-get install -d -o dir::cache::archives="/some/cache/dir" <package>

This command will download (and only download, not install) the relevant .deb files for <package> to /some/cache/dir. The directory will contain the .deb files for the package, its dependencies, a lock file and 'partial' directory (which should be empty). Filtering out the exact .deb file you need should be trivial.

  • Unfortunately, apt-get install requires superuser access.
    – mikosz
    Apr 8 '13 at 8:37

apt-get download also allows you to set target release. Wouldn't it help?

apt-get download package/testing

Comment to #1 (cannot use comments) - adding parameter --print-uris to apt-get install does not require root rights (but you have to download it itself – best with wget -i FILE_LIST).

  • Mikolaj Radwan seems to be looking for a way to fetch specific versions possibly using expressions for later script usage. This would just allow the download of the current package.
    – Will
    May 22 '13 at 20:38

Without SU privs you can still run apt-cache and combine with filtering to get that info. Use something like:

On Debian 5:

apt-cache show <pkg> | head | grep -i version 

On 6 you can use:

apt-cache show <pkg> | tail | grep -i version

Apt-cache seems to have changed behavior in the ordering of the list between 5 and 6 so that on 6 the newest one comes last.

One word of caution is that if you are using this output as you say "to fetch the same version as the one that would be downloaded using such dependency", the version of the package available may change if you run apt-get update (with su privs of course), or if that has been set to automatically run and happens in between when you gathered the version, and when you run the script that installs things expecting that to be the version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.