8

I can get a list of all available packages and their details using the following command:

apt-cache search .

Which outputs a list of packages which looks like this:

i   0ad                - Real-time strategy game of ancient warfare
i   0ad-data           - Real-time strategy game of ancient warfare (data files)                            
i   0ad-data-common    - Real-time strategy game of ancient warfare (common data files)                        
p   0ad-dbg            - Real-time strategy game of ancient warfare (debug)                                    
p   0xffff             - Open Free Fiasco Firmware Flasher                                                     
p   2ping              - Ping utility to determine directional packet loss                                     
p   2vcard             - perl script to convert an addressbook to VCARD file format                            
p   3270-common        - Common files for IBM 3270 emulators and pr3287                                        
p   389-admin          - 389 Directory Administration Server 
...

How can I get such a list of packages for a version of Ubuntu which I don't have installed?

So, specifically, where can I download the database of all available packages for a specific version of Ubuntu, and how do I get the details (Possibly including version, size, long description...) from it, in plaintext or in a format which is easy to parse with a script?

muru
  • 207,970
Jonas Czech
  • 4,047
  • For me apt-cache search . or apt-cache search '' out put 23xx lines which is in fact the whole amount of all possible packages including different DE versions. – Videonauth Jun 12 '16 at 16:35
  • 2
    If this didn't have a bounty, I'd suggest this to be a dupe of http://askubuntu.com/q/722439/158442 – muru Jun 19 '16 at 18:46

5 Answers5

11

1. On-line

I prefer use of http://packages.ubuntu.com/ as muru's answer.

  • Pro: It has always updated list, but includes only official repository.
  • Con: It is a nightmare to follow PPA's and external repositories one by one.

2. For Off-line use, Manual

Otherwise looking for an off-line solution then you should be MR. APT and start downloading them from http://archive.ubuntu.com/ubuntu/dists/.

p=$(pwd); for c in main universe multiverse restricted; do for u in "" -security -updates; do for a in binary-amd64 binary-i386; do mkdir trusty${u}_${c}_$a; cd trusty${u}_${c}_$a; wget http://archive.ubuntu.com/ubuntu/dists/trusty$u/$c/$a/Packages.bz2; cd $p; done; done; done;

Results:

$ tree
.
├── trusty_main_binary-amd64
│   └── Packages.bz2
├── trusty_main_binary-i386
│   └── Packages.bz2
├── trusty_multiverse_binary-amd64
│   └── Packages.bz2
├── trusty_multiverse_binary-i386
│   └── Packages.bz2
├── trusty_restricted_binary-amd64
│   └── Packages.bz2
├── trusty_restricted_binary-i386
...

3. For Off-line use, using apt-cache/overlay-filesystem/chroot

Going bad, advanced setup:

  • OverlayFS: Create a lightweight partial copy of current FS tree, with modification. Objective is change only release name in source.lists . How does OverlayFS work is explained here in this post or from ArchLinux Wiki. Alternative way would be: fuse-overlayfs
  • chroot: Get shell command in that modified file tree. Alternative way: overlayroot-chroot
  • apt-cache: Search for packages

I'm going to use a custom sources.list* with same apt-cache installed on 16.04, but apt will not overwrite the 16.04 real lists files in /var/lib/apt/lists/, All changes (mine or generated ones) will go to the overlay file-system.

Setup:

sudo apt-get install chroot
mkdir sandbox0
cd sandbox0
mkdir upper work merged
sudo mount -t overlay overlay -o lowerdir=/,upperdir=./upper,workdir=./work ./merged
sudo chroot merged/
echo "deb http://archive.ubuntu.com/ubuntu/ trusty universe multiverse main restricted" > /etc/apt/sources.list
rm -r /etc/apt/sources.list.d/*
apt-get update
exit

Use: (you may prepare a script)

sudo mount -t overlay overlay -o lowerdir=/,upperdir=./upper,workdir=./work ./merged
sudo chroot merged/

apt-cache ...

user.dz
  • 49,295
  • 1
    Can you please explain what your sudo mount -t overlay overlay -o lowerdir=/,upperdir=./upper,workdir=./work ./merged command does ? – SebMa Dec 05 '24 at 21:41
  • @SebMa It takes "/" as read-only, and mounts it into "./merged", then overlays "./merged" with "./upper" . Added references for OverlayFS use in the answer. – user.dz Dec 06 '24 at 08:36
6

Use chdist. This command allows you to run apt-get and apt-cache as usual, but for a different release of Ubuntu (or Debian or in fact any other Debian-derived distribution).

It also provides a wrapper around grep-dctrl which easily allows you to search and report on metadata fields.

Robie Basak
  • 15,930
  • 1
    Thanks, this seems to offer exactly what I need, and looks like it'll be easier to get working than the method from Sneetsher's answer. – Jonas Czech Jun 25 '16 at 14:18
  • 1
    Great, this is the canonical answer. You beat me :D. Nice to know about such tool. – user.dz Jun 25 '16 at 18:26
2

You can install html2text and try searching in xenial (for example) for ocaml packages :

curl -k -s https://packages.ubuntu.com/xenial/allpackages | html2text | egrep '^ +ocaml'
SebMa
  • 2,955
2

You already have the command to list all possible posted, but ok lets go a bit deeper shall we? So apt-cache search . or apt-cache search '' output around 2300+ lines which is in fact the whole amount of all possible packages including different DE versions.

To make it more easy you could only get the names with:

apt-cache search '' | sort -d | awk '{print $1}'

Or is you like more information and dont mind a long long list you could roll that through apt-cache policy:

apt-cache policy $(apt-cache search '' | sort -d | awk '{print $1}')
Videonauth
  • 33,845
  • 4
    Yes, but I asked "for a specific version of Ubuntu which I don't have installed ?", so I don't have this list in my apt-cache yet, I need to get it from the internet somehow. Do you know how I could do that ? – Jonas Czech Jun 12 '16 at 16:47
  • mhmm yes at least for the desktop versions there are manifest files, let me find the link to one ok? – Videonauth Jun 12 '16 at 16:49
  • http://releases.ubuntu.com/16.04/ubuntu-16.04-desktop-amd64.manifest thats the one for 16.04 LTS, and 14.04.4 here http://releases.ubuntu.com/14.04/ubuntu-14.04.4-desktop-amd64.manifest then you have them as file form. – Videonauth Jun 12 '16 at 16:51
  • Unfortunately that isn't the complete list of all available packages (It's just the list of packages on the ISO), which is what I need, nor does it have the descriptions and other data, which I need as well. Any other possibilities ? – Jonas Czech Jun 12 '16 at 16:53
  • Not that I know, really this is the best guess I can give you. the lists in the manifest only not contain the canonical stuff I think. they are beside that pretty complete. – Videonauth Jun 12 '16 at 16:58
  • Okay, thanks anyway, and +1 because of the useful information on how to get the long list with more details. Thanks :-) – Jonas Czech Jun 12 '16 at 17:00
1

Just to complete @Robie-Basak 's answer, here an example with the chdist tool querying Ubuntu Trusty (14.04) sources :

$ chdist create 14.04
Now edit /home/myName/.chdist/14.04/etc/apt/sources.list
Run chdist apt-get 14.04 update
And enjoy.
$ chdist list
14.04
$ cat /etc/apt/sources.list | sed s/$(lsb_release -sc)/trusty/ | tee ~/.chdist/14.04/etc/apt/sources.list >/dev/null
$ chdist apt-get 14.04 update
Ign:1 http://fr.archive.ubuntu.com/ubuntu trusty InRelease
Hit:2 http://fr.archive.ubuntu.com/ubuntu trusty-updates InRelease
Hit:3 http://fr.archive.ubuntu.com/ubuntu trusty-backports InRelease
Hit:4 http://fr.archive.ubuntu.com/ubuntu trusty-security InRelease
Hit:5 http://fr.archive.ubuntu.com/ubuntu trusty Release
Reading package lists... Done
$ chdist apt-cache 14.04 policy ocaml-nox
ocaml-nox:
  Installed: (none)
  Candidate: 4.01.0-3ubuntu3.1
  Version table:
     4.01.0-3ubuntu3.1 500
        500 http://fr.archive.ubuntu.com/ubuntu trusty-updates/main amd64 Packages
        500 http://fr.archive.ubuntu.com/ubuntu trusty-security/main amd64 Packages
     4.01.0-3ubuntu3 500
        500 http://fr.archive.ubuntu.com/ubuntu trusty/main amd64 Packages
$

And if you are behind a proxy defined in the /etc/apt/apt.conf.d/00aptproxy file (for example), than you must type this command BEFORE typing your chdist apt-get 14.04 update :

$ cp -puv /etc/apt/apt.conf.d/00aptproxy ~/.chdist/14.04/etc/apt/apt.conf.d/00aptproxy
'/etc/apt/apt.conf.d/00aptproxy' -> '/home/myName/.chdist/14.04/etc/apt/apt.conf.d/00aptproxy'
$
SebMa
  • 2,955