2

I am studying for LPIC exam and one of the tasks in the lab is to find details about package with dpkg -p, concretely about vim with dpkg -p vim. In the solution, the command produces information about the package, but my output is:

root@home:~# dpkg -p vim
dpkg-query: package 'vim' is not available
Use dpkg --info (= dpkg-deb --info) to examine archive files,
and dpkg --contents (= dpkg-deb --contents) to list their contents.

Vim is installed, I am using it offen and it can also be found on system

root@home:~# type vim
vim is hashed (/usr/bin/vim)
root@home:~# which vim
/usr/bin/vim

I thought the dpkg -p is somehow broken, but it works with other packages (I have tried several and they all worked fine):

root@home:~# dpkg -p eject
Package: eject
Priority: important
Section: utils
Installed-Size: 160
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
...

My system (VPS) info is

Ubuntu 18.04.5 LTS
Linux 4.15.0-143-generic #147-Ubuntu SMP Wed Apr 14 16:10:11 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Why can I not reproduce the solution from the course? Thank you!

Pan Vi
  • 125

1 Answers1

2

In a distant time, dpkg wasn't used by apt which didn't exist yet but by other front-ends, like dselect. Those tools took care of updating the available list of packages which ends in the file /var/lib/dpkg/available eg when running dselect update. dpkg -p's feature depends on an up to date available list file.

That's not always the case today. apt doesn't care about /var/lib/dpkg/available at all. There might be other (possibly GUI) tools that still get this file updated somehow, and thus /var/lib/dpkg/available might be partially filled-in.

The manpage for dpkg (or dpkg-query) tells:

-p, --print-avail package-name...

Display details about package-name, as found in /var/lib/dpkg/available. Users of APT-based frontends should use apt-cache show package-name instead.

There's also:

--update-avail [Packages-file]
--merge-avail [Packages-file]

Update dpkg's and dselect's idea of which packages are available. With action --merge-avail, old information is combined with information from Packages-file. With action --update-avail, old information is replaced with the information in the Packages-file. The Packages-file distributed with Debian is simply named «Packages». If the Packages-file argument is missing or named «-» then it will be read from standard input (since dpkg 1.17.7). dpkg keeps its record of available packages in /var/lib/dpkg/available.

You can use apt-cache dumpavail to generate on-the-fly an available file format output:

dumpavail dumpavail prints out an available list to stdout. This is suitable for use with dpkg(1) and is used by the dselect(1) method.

And merge the result (this example wasn't run on Ubuntu):

# apt-cache dumpavail | dpkg --merge-avail -
Updating available packages info, using -.
Information about 119859 packages was updated.

dpkg -p vim will now work, but it would have probably been simpler to use directly apt-cache show vim or apt show vim.

Conclusion: some LPIC questions are probably outdated, but to get your exam, you'll have to learn specific exam things that aren't used anywhere anymore.

A.B
  • 36,364
  • 2
  • 73
  • 118
  • Note that I don't know if the vim package is installed rather than available in OP's case but this doesn't change this. There are several packages providing the vim packages (in addition of vim itself). Try apt-cache showpkg vim to get a list of packages that can provide vim (eg: vim-nox, vim-gtk3, vim-gtk, vim-athena) – A.B Jun 06 '21 at 18:19
  • 1
    +1. This is why I still use dselect update, but with apt install or apt dist-upgrade. Also because I never use dselect for anything else any more so I can just type !dsel to take advantage of bash's history. – cas Jun 07 '21 at 04:15