4

How do I get the real full package name (including the version) that would be installed if I ran apt-get install pseudo-package-name?

This is related to this previous question: Get the kernel version from lts package?

Example:

apt-get install linux-image-generic-lts-trusty

would install (as of right now on my 32-bit Trusty server):

linux-image-3.13.0-35-generic

I've tried the following, but none give me the answer. I'm trying to script this so I can just grab the linux-headers.

$ sudo apt-get install -qqs linux-image-generic-lts-trusty
Inst linux-image-generic-lts-trusty (3.13.0.35.42 Ubuntu:14.04/trusty-updates [i386])
Conf linux-image-generic-lts-trusty (3.13.0.35.42 Ubuntu:14.04/trusty-updates [i386])
$ apt-cache depends linux-image-generic-lts-trusty
linux-image-generic-lts-trusty
  Depends: linux-image-generic
$ apt-cache depends linux-image-generic
linux-image-generic
  Depends: linux-image-3.13.0-35-generic
  Depends: linux-image-extra-3.13.0-35-generic
  Depends: linux-firmware
$ apt-cache policy linux-image-generic-lts-trusty
linux-image-generic-lts-trusty:
  Installed: (none)
  Candidate: 3.13.0.35.42
  Version table:
     3.13.0.35.42 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu/ trusty-security/main i386 Packages
     3.13.0.24.28 0
        500 http://us.archive.ubuntu.com/ubuntu/ trusty/main i386 Packages

After some exploration of /var/lib/{apt,dpkg}, I relealized that there's not a generic, scriptable answer to this problem. So, similar to the answers below from @mchid and @muru, I did it like this:

#!/bin/bash

metapackage=linux-image-generic-lts-trusty
linux_package_version=$(apt-cache policy $metapackage |\
    sed -nE '/Candidate:/ s,[^[:digit:]]*([[:digit:]\.]+)\.([[:digit:]]+)\.[[:digit:]]+,\1-\2,p')

apt-get download linux-headers-${linux_package_version}-generic linux-headers-${linux_package_version})

3 Answers 3

4

First, you must show exactly what package the metapackage provides:

example:

apt-cache show linux-image-generic-lts-trusty | grep Depends:

output:

Depends: linux-image-generic
Depends: linux-image-generic

Now, if you type the specific package of the metapackage you will get your exact result:

apt-cache show linux-image-generic | grep Depends:

output:

Depends: linux-image-3.13.0-35-generic, linux-image-extra-3.13.0-35-generic, linux-firmware
Depends: linux-image-3.13.0-24-generic, linux-image-extra-3.13.0-24-generic, linux-firmware

The newest version is always installed unless otherwise specified like in the following example:

sudo apt-get install linux-image-3.13.0-24-generic

Alternatively, if you just want the version you could type the following command or a variation there of instead:

apt-cache show linux-image-generic-lts-trusty | grep Version:

output:

Version: 3.13.0.35.42
Version: 3.13.0.24.28
1
  • I ended up digging around in /var/lib/{apt,dpkg} and realized that there's no absolute answer. Since I was looking for the linux version explicitly, I tailored my solution using similar techniques above. I'll post my exact answer at the end of the question.
    – Harvey
    Sep 17, 2014 at 19:48
3

The problem is the dependency:

linux-image-generic-lts-trusty
└── linux-image-generic
    └── linux-image-3.13.0-35-generic

Because of this, you may not directly get information on which package will be installed. You'll need to use something like apt-rdepends.

1

In general you cannot. There are packages such as "email-client" that do not provide a dependency chain that can be followed and resolved.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .