如何修复命令未找到数据库?

如何修复命令未找到数据库?

我最近安装的 Ubuntu 系统目前遇到了 command-not-found 钩子的问题:

josh@sirius:~$ invalid-command
Unable to open binary database /usr/share/command-not-found/programs.d/i386-main.db: File read error
Unable to open binary database /usr/share/command-not-found/programs.d/i386-multiverse.db: File read error
Unable to open binary database /usr/share/command-not-found/programs.d/i386-restricted.db: File read error
Unable to open binary database /usr/share/command-not-found/programs.d/i386-universe.db: File read error
invalid-command: command not found

我尝试过重新安装和dpkg-reconfigure运行这两个command-not-found{,-data}程序,但似乎都没有解决问题。删除这些文件安全吗?还是我必须运行某个程序来重新创建它们?我应该补充一点,这原本是一个 32 位安装,我重新安装了 64 位,没有格式化磁盘。

答案1

20.04.4LTS 上,这对我有帮助:

$ sudo apt install --reinstall command-not-found

-data包裹已不存在。

我得到了类似的东西:

$ kbounce
Sorry, command-not-found has crashed! Please file a bug report at:
https://bugs.launchpad.net/command-not-found/+filebug
Please include the following information with the report:

command-not-found version: 0.3
Python version: 3.8.5 final 0
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal
Exception information:

unable to open database file
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/CommandNotFound/util.py", line 23, in crash_guard
    callback()
  File "/usr/lib/command-not-found", line 90, in main
    cnf = CommandNotFound.CommandNotFound(options.data_dir)
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 79, in __init__
    self.db = SqliteDatabase(dbpath)
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 12, in __init__
    self.con = sqlite3.connect(filename)
sqlite3.OperationalError: unable to open database file

现在,我得到:

$ kbounce

Command 'kbounce' not found, but can be installed with:

sudo apt install kbounce

编辑 2020-12-16

重启后问题又出现了。我调试了一下/usr/lib/python3/dist-packages/CommandNotFound/db/db.py,发现如下:

$ ls /var/lib/command-not-found/ -l
total 3076
-rw-r----- 1 root root 3141632 gru 16 08:17 commands.db
-rw-r----- 1 root root    3253 gru 16 08:17 commands.db.metadata

因此,数据库在那里,但是权限错误。

所以我执行了:

$ sudo chmod -R o+r /var/lib/command-not-found/

现在,它又能正常工作了。

答案2

64 位版本的数据库文件名为amd64-*.db,而 32 位版本的数据库文件名为i386-*.db。因此,显然您安装了 32 位软件包,而您应该安装 64 位软件包。

这输出什么?

apt-cache policy command-not-found{,-data}

相关内容