我最近从 Ubuntu 18.04 升级到了 20.04。
升级后,我注意到了一点不同。以前,如果我输入系统上不可用的命令,它会自动推荐软件包名称(假设该命令确实存在于某些存储库中)。例如:
$ htop
Command 'htop' not found, but can be installed with:
sudo apt install htop
但现在,我只得到:
$ htop
htop: command not found
即现在缺少 apt install 的建议。
知道是什么导致了这种行为的改变吗?
答案1
我发现这是因为缺少软件包(我一定是在升级到 Focal 时意外删除了它,或者它被无意中“自动删除”了)。获取自动建议的方法是安装软件包command-not-found
:
$ sudo apt search command-not-found
Sorting... Done
Full Text Search... Done
command-not-found/focal-updates,now 20.04.4 all [residual-config]
Suggest installation of packages in interactive bash sessions
packagekit-command-not-found/focal 1.1.13-2ubuntu1 amd64
Offer to install missing programs automatically
python3-commandnotfound/focal-updates,now 20.04.4 all [installed,auto-removable]
Python 3 bindings for command-not-found.
之前和之后的示例:
$ smartctl
smartctl: command not found
$ sudo apt install command-not-found -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
command-not-found
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 5240 B of archives.
After this operation, 35.8 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 command-not-found all 20.04.4 [5240 B]
Fetched 5240 B in 0s (18.5 kB/s)
Selecting previously unselected package command-not-found.
(Reading database ... 43980 files and directories currently installed.)
Preparing to unpack .../command-not-found_20.04.4_all.deb ...
Unpacking command-not-found (20.04.4) ...
Setting up command-not-found (20.04.4) ...
$ smartctl
Command 'smartctl' not found, but can be installed with:
sudo apt install smartmontools
$