11
October
2023
Solving the problem "Could Not Find Command-not-found database"
16:44

Solving the problem "Could Not Find Command-not-found database"

11 October 2023 16:44

The "Command-not-found" stub program is triggered when a user mistakenly enters in the terminal a non-existent command name, such as "foobar". In some cases, the command-not-found program doesn't work. How can I fix it?

Introduction

As you know, the programs are contained in packages, and the packages are managed by the apt command based on the contents of the file /etc/apt/sources.list and files *.list in subfolder sources.list.d. When changing the composition of the repositories, the "command-not-found" program database, which is located along the path /var/lib/command-not-found/, should be automatically updated. The symptoms of the problem I have encountered are the following:

1) When performing an incorrect command, a message is displayed
...
Could not find command-not-found database. Run 'sudo apt update' to populate it.
... : command not found

2) There is no database for the command, which is the fact:

ls -l /var/lib/command-not-found/ 

0 files

Cause

After the call of utility apt-get update worked out, a Bash script must run: /etc/apt/apt.conf.d/50command-not-found. Linux LXLE doesn't have such a file, but Linux Mint does. The LXLE developers forgot to include the file 50command-not-found?

Solution: Method No. 1

Copy the file /etc/apt/apt.conf.d/50command-not-found from Linux Mint to LXLE or create it manually.
script

The source text is 50command-not-found:
50command-not-found.zip

After that, update the cache by calling apt update. It will also create SQLite database files for the "command-not-found" program in the /var/lib/command-not-found/ directory. The files "commands.db" and "commans.db.metadata" are created by the Python script /usr/lib/cnf-update-db. (To do this, Python 2.7 or higher must be installed on the operating system - the condition in Linux LXLE is fulfilled).

Solution: Method No. 2

Nach der Aktualisierung der Pakete apt update müssen Sie die folgenden 2 Befehle im Terminal manuell mit den Rechten von sudo ausführen:

sudo rm -f /var/lib/command-not-found/*.*
sudo /usr/lib/cnf-update-db

Non-working solution (from the Internet)

– can be suitable for other distributions

Reinstalling the utility:
sudo apt purge command-not-found
sudo apt install command-not-found
sudo apt update

Testing

Check the presence of files commands.db and commands.db.metadata:

ls -l /var/lib/command-not-found/

Total 3156
-rw-r--r-- 1 root root 3223552 окт 11 15:53 commands.db
-rw-r--r-- 1 root root 3260 окт 11 15:53 commands.db.metadata
User@host:~$

Führen Sie den „falschen“ Befehl aus, zum Beispiel „Appt“:

appt

The Appt command was not found. Perhaps you meant:
command 'ppt' from deb bsdgames (2.17-29)
command 'apt' from deb apt (2.4.10)
command 'aapt' from deb aapt (1:10.0.0+r36-3)
Try: sudo apt install

Message "Could not find command-not-found database. Run 'sudo apt update' to populate it." it is no longer displayed.' That's fix.