在“当前未安装程序‘x’”后要求安装程序

Ger*_*ger 19 command-line

如果您尝试执行未安装的程序,您将收到一条消息

The program 'x' is currently not installed. You can install it by typing: 
sudo apt-get install x
Run Code Online (Sandbox Code Playgroud)

而不是让您为您安装程序,您必须键入实际命令。如何改变这种行为?

Ger*_*ger 18

负责此行为的包是command-not-found安装找不到命令包,并且它已经包含所需的行为,尽管默认情况下它是禁用的。您可以通过将以下行添加到您的~/.bashrc

export COMMAND_NOT_FOUND_INSTALL_PROMPT=1
Run Code Online (Sandbox Code Playgroud)

现在行为更改为

The program 'x' is currently not installed. You can install it by typing:
sudo apt-get install x
Do you want to install it? (N/y)
Run Code Online (Sandbox Code Playgroud)

注意: 如果您收到有关 python 崩溃的消息(特别是AttributeError: 'str' object has no attribute 'decode'),这是错误 1073919。Raring 和 Saucy 的修复程序已经可用。或者(仅限高级用户),您可以更改文件/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py,请参阅错误报告所附的差异以了解需要更改的行。

编辑:该修复程序现已在 Raring (SRU) 的 0.3ubuntu7.1 版本和 Saucy 的 0.3ubuntu8 版本中发布。