4

There's a really great package that I love called command-not-found. When you type unknown commands, it searches through apt and suggests packages to install. It has worked in Raspberry Pi before.

However if you try it now…

sudo apt-get install command-not-found

Package is installed. According to docs you need to generate its database:

sudo update-command-not-found

It however finishes under half a second with return code 0, which is suspicious and strange. I've used it before in a full PC and it takes at least 20 seconds.

Then, no matter how many times I try to update-command-not-found, or restart my bash session, the database is never there.

$ aoeuaoeuaoeu
Could not find the database of available applications, run update-command-not-found as root to fix this
aoeuaoeuaoeu: command not found

If you man update-command-not-found, it references the file/folder (I dunno) /var/cache/apt/apt-file, which doesn't seem to be there at all. Should it? Or should update-command-not-found look elsewhere?

  • You might need to reload your shell to get it to work. You can log out and back in or do exec bash. – chicks Nov 18 '17 at 23:03
  • I've wrestled with this for a while before coming to SE. Plenty of re-logins. Also the error message makes it clear that command-not-found is in the session, it just has an empty database (which will remain empty). I will edit the message to make it clear that the session is different – Ekevoo Nov 19 '17 at 0:27
  • 2
    Did you run apt-file update before updating the command-not-found cache? – RubberStamp Nov 19 '17 at 1:46
3

Short answer from the comment section

Run apt-file update before running update-command-not-found

Longer Answer

The utility command-not-found includes a dependency on the apt search utility apt-file

#apt-cache depends command-not-found

command-not-found
  Depends: <python:any>
    python:i386
    python
  Depends: apt-file
  Depends: python-gdbm
  Depends: lsb-release

So, on a system where apt-file has not been installed, installing command-not-found will also install apt-file. However, apt-file is not the same program as apt, and seemingly does not rely entirely on the apt-get update cache. So, in order to properly setup apt-file the apt-file update command is required.

There is a clue in apt-get output when install command-not-found and pulling in apt-file as a dependency.

#apt-get install command-not-found
...
Setting up apt-file (3.1.5) ...
The system-wide cache is empty. You may want to run 'apt-file update'
as root to update the cache.

Strangely, when paging through the apt-file manpage, the update command is listed as deprecated and results in a call to apt update. I haven't looked too closely at the differences of where the package cache is stored or if there is some sort of identifier placed in the apt cache file to indicate that apt versus apt-get has been used to update the cache. So, I'm uncertain as to why apt update is needed versus apt-get update. I suppose it would be complicated to include updating the appropriate cache during the setup of apt-file, because dpkg is already running with a lock file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.