How to list available versions on apt

On Ubuntu servers, this command lists all available versions on apt.

List versions

$ apt-cache madison elixir
    elixir |   1.10.3-1 | http://binaries.erlang-solutions.com/debian focal/contrib amd64 Packages
    elixir |   1.10.2-1 | http://binaries.erlang-solutions.com/debian focal/contrib amd64 Packages
    elixir | 1.9.1.dfsg-1.3 | http://ca.archive.ubuntu.com/ubuntu focal/universe amd64 Packages

And also there are policy or showpkg subcommands.

$ apt-cache policy elixir
elixir:
  Installed: 1.10.3-1
  Candidate: 1.10.3-1
  Version table:
 *** 1.10.3-1 999
        999 http://binaries.erlang-solutions.com/debian focal/contrib amd64 Packages
        100 /var/lib/dpkg/status
     1.10.2-1 999
        999 http://binaries.erlang-solutions.com/debian focal/contrib amd64 Packages
     1.9.1.dfsg-1.3 500
        500 http://ca.archive.ubuntu.com/ubuntu focal/universe amd64 Packages

Install specific version

apt install elixir=1.10.3-1

Contents