78

Using APT, you can install a specific version of a package using:

apt-get install package=1.0

But you can't do

apt-get install package=1.*

So, how can I find out which versions are avaliable for package on a specific repository, or in all repositories in my /etc/apt/sources.list?

Camilo Martin
  • 2,604
  • 4
  • 32
  • 41
  • See also http://stackoverflow.com/questions/18885820/how-to-check-the-version-before-install-packages-using-apt-get – rogerdpack Jan 09 '15 at 00:07

4 Answers4

118

Just as an addendum

apt-cache madison <<package name>>

will list the versions available from all your sources.

apt-cache madison vim
   vim | 2:7.3.547-1 | http://debian.mirrors.tds.net/debian/ unstable/main amd64 Packages
   vim | 2:7.3.429-2 | http://debian.mirrors.tds.net/debian/ testing/main amd64 Packages
   vim | 2:7.3.429-2 | http://http.us.debian.org/debian/ testing/main amd64 Packages
   vim | 2:7.3.429-2 | http://debian.mirrors.tds.net/debian/ testing/main Sources
   vim | 2:7.3.547-1 | http://debian.mirrors.tds.net/debian/ unstable/main Sources

madison is an apt-cache subcommand, man apt-cache says:

apt-cache's madison command attempts to mimic the output format and a subset of the functionality of the Debian archive management tool, madison. It displays available versions of a package in a tabular format. Unlike the original madison, it can only display information for the architecture for which APT has retrieved package lists (APT::Architecture).

lornix
  • 11,240
  • 2
  • 30
  • 34
  • 7
    Madison? Is that a parameter to apt-cache or a package name? I'm not using an apt-get distro anymore (but +1 just in case) – Camilo Martin Jun 17 '12 at 19:56
  • 5
    parameter. Don't feel bad, it was one of those chance discoveries for me too. There's a web page (app?) on the Debian site which shows the same information, which I suppose was first, and someone coded it for apt-cache. Quite handy. – lornix Jun 17 '12 at 19:57
  • Wow, quite handy indeed. I'll change the accept to this because it's just what I wanted (at the time) and comes built-in without grepping it. – Camilo Martin Jun 18 '12 at 21:25
  • 1
    This doesn't work for all packages. – Cerin Feb 22 '14 at 15:32
  • Now THAT is an AWESOME tidbit! tells version and repo, I love it! – Dennis Jun 26 '15 at 06:16
  • Can you install package for which line ends with `Sources`? How can you do it? – nuoritoveri May 12 '16 at 08:28
  • 1
    @nuoritoveri The **Sources** sources are repositories which contain the source code of the various programs and packages. The source code may be downloaded using the `apt-get source XYZZY` command to download the source for the _XYZZY_ package. See the _apt-get_ **man page** (`man apt-get`) for more details. – lornix May 12 '16 at 09:19
  • 6
    Really, `madison`? Why not `terry`? Thanks for this – smac89 Dec 08 '17 at 21:36
  • it's hard to believe there is only 1 version of this package. are we sure the answer is correct? ```apt-cache madison openssh-client openssh-client | 1:9.2p1-2 | http://deb.debian.org/debian bookworm/main amd64 Packages``` – majorgear Aug 21 '23 at 16:44
28

The apt-cache show <Package> shows the package descriptions of all the versions your debian installation can install (i.e. from cached list of packages available from the repos listed in sources.list). So I guess you could try something like (for e.g.):

# apt-cache show package | grep Version
Version 1.0
Version 0.9-2squeeze1

The apt-cache show would give you much more info than just versions.

Anil
  • 618
  • 5
  • 6
14
apt-cache policy gdb

Sample output:

gdb:
  Installed: 7.7.1-0ubuntu5~14.04.2
  Candidate: 7.7.1-0ubuntu5~14.04.2
  Version table:
 *** 7.7.1-0ubuntu5~14.04.2 0
        500 http://fr.archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        100 /var/lib/dpkg/status
     7.7-0ubuntu3 0
        500 http://fr.archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

So we see that there are two versions of GDB available:

  • 7.7.1-0ubuntu5~14.04.2
  • 7.7-0ubuntu3

Meaning of the output:

  • 1
    Thanks, this seems more detailed than `apt-cache madison` (but harder to parse). – Camilo Martin Jul 26 '15 at 18:26
  • @CamiloMartin it's also localized. So keywords like "installed" and "candidate" will be different if the user is using a different language. – bleater Apr 17 '23 at 00:07
3

A command that is specifically intended for this is apt-show-versions. You often have to install it, but then can run apt-show-versions -a and it will show you the version number, the distribution (i.e. testing, stable, unstable, backports, etc.) where that can be found, and finally tell you if the version you have installed is up to date or not.

It does not give you as much information as apt-cache, but gives you pretty much what you need, as you can then install from the correct repository (using aptitude / apt-get -t) or simply install using the correct version number in the form you noted.

ShankarG
  • 876
  • 1
  • 9
  • 23