【Linux】Linux执行未识别命令时提示:Sorry, command-not-found has crashed


一、问题描述

正如前一篇博客展示的那样,服务器环境有点乱乱的,这不,第二个异常点就来了。笔者准备使用vmtouch命令,系统居然和我这样说:

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.10 final 0
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal
Exception information:
......

看起来是系统找不到vmtouch命令,调用command-not-found时又出了问题。


二、解决方案

去因特耐特找寻问题答案,有人[1]说是编码有问题,并给出了几行命令,但是笔者尝试过后发现并没有什么变化,但还是附命令如下(诸位判断清楚自己遇到问题的真正原因再执行命令):

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
sudo locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales

之后笔者在StackOverflow[2]找到了和我问题类似的贴子,解决方案如下。

一位名为Sajjad Ahmad的用户这样描述:

If any of the above solutions don't work, it means "command-not-found" utility itself is misconfigured.
Simply remove the utility, and install again.
如果上述任何解决方案都不起作用,则表示“command-not-found”程序本身配置错误。
只需删除该程序,然后再次安装。

上述解决方案指[1]。

对我有用的解决步骤为:

  1. 删除command-not-found程序,执行sudo apt purge command-not-found
    输出如下:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      gir1.2-snapd-1 libextutils-depends-perl python3-dateutil python3-debconf python3-requests-unixsocket python3-yaml software-properties-common
      update-notifier-common
    Use 'sudo apt autoremove' to remove them.
    The following packages will be REMOVED:
      command-not-found*
    0 upgraded, 0 newly installed, 1 to remove and 1274 not upgraded.
    After this operation, 27.6 kB disk space will be freed.
    Do you want to continue? [Y/n] Y
    (Reading database ... 260108 files and directories currently installed.)
    Removing command-not-found (0.3ubuntu16.04.2) ...
    (Reading database ... 260102 files and directories currently installed.)
    Purging configuration files for command-not-found (0.3ubuntu16.04.2) ...
    

    看起来删除成功了。

  2. 再次安装command-not-found程序,执行sudo apt install command-not-found
    输出如下:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:
    
    The following packages have unmet dependencies:
     command-not-found : Depends: python3-commandnotfound (= 18.04.6) but 20.04.2 is to be installed
    E: Unable to correct problems, you have held broken packages.
    

    看起来又出现了依赖问题,依赖低版本但是已经安装了高版本,参考我的博客,老解决方法,我直接remove

  3. 执行sudo apt remove python3-commandnotfound ,提示如下:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      gir1.2-snapd-1 libextutils-depends-perl python3-dateutil python3-debconf python3-requests-unixsocket python3-yaml software-properties-common
      update-notifier-common
    Use 'sudo apt autoremove' to remove them.
    The following packages will be REMOVED:
      python3-commandnotfound sessioninstaller
    0 upgraded, 0 newly installed, 2 to remove and 1274 not upgraded.
    After this operation, 297 kB disk space will be freed.
    Do you want to continue? [Y/n] Y
    (Reading database ... 260101 files and directories currently installed.)
    Removing sessioninstaller (0.20+bzr150-0ubuntu4.1) ...
    Removing python3-commandnotfound (20.04.2) ...
    Processing triggers for man-db (2.7.5-1) ...
    
  4. 重新安装command-not-found,执行sudo apt install command-not-found
    输出如下:

    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    The following packages were automatically installed and are no longer required:
      gir1.2-snapd-1 libextutils-depends-perl python3-dateutil python3-debconf python3-requests-unixsocket python3-yaml software-properties-common
      update-notifier-common
    Use 'sudo apt autoremove' to remove them.
    The following additional packages will be installed:
      command-not-found-data python3-commandnotfound
    The following NEW packages will be installed:
      command-not-found python3-commandnotfound
    The following packages will be upgraded:
      command-not-found-data
    1 upgraded, 2 newly installed, 0 to remove and 1273 not upgraded.
    Need to get 1,023 kB of archives.
    After this operation, 1,112 kB disk space will be freed.
    Do you want to continue? [Y/n] Y
    Get:1 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 command-not-found-data amd64 18.04.6 [1,009 kB]
    Get:2 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 python3-commandnotfound all 18.04.6 [9,032 B]
    Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 command-not-found all 18.04.6 [5,208 B]
    Fetched 1,023 kB in 4s (235 kB/s)          
    (Reading database ... 260067 files and directories currently installed.)
    Preparing to unpack .../command-not-found-data_18.04.6_amd64.deb ...
    Unpacking command-not-found-data (18.04.6) over (0.3ubuntu16.04.2) ...
    Selecting previously unselected package python3-commandnotfound.
    Preparing to unpack .../python3-commandnotfound_18.04.6_all.deb ...
    Unpacking python3-commandnotfound (18.04.6) ...
    Selecting previously unselected package command-not-found.
    Preparing to unpack .../command-not-found_18.04.6_all.deb ...
    Unpacking command-not-found (18.04.6) ...
    Setting up command-not-found-data (18.04.6) ...
    Setting up python3-commandnotfound (18.04.6) ...
    Setting up command-not-found (18.04.6) ...
    

    安装成功,测试一下,可以看到能够正确提示缺少的包:

    root@ln01:/home/tangjiahao# testcommand
    testcommand: command not found
    root@ln01:/home/tangjiahao# vmtouch
    Command 'vmtouch' not found, but can be installed with:
    apt install vmtouch
    root@ln01:/home/tangjiahao# 
    

    在这里插入图片描述问题解决


三、总结

以上就是今天要分享的内容,本文介绍了如何以重装command-not-found解决Sorry, command-not-found has crashed提示的问题。另外vmtouch是个用于了解和控制 unix 和类 unix 系统的文件系统缓存的工具,有机会讲一下如何使用(挖坑😬)。
如果本文能给你带来帮助的话,点个赞鼓励一下作者吧!💪

四、引用参考

[1] 关于ubuntu上执行错误命令报错:http://www.javashuo.com/article/p-uekwrird-n.html
[2] command not found message:https://stackoverflow.com/questions/19873430/command-not-found-message-when-i-try-to-add-command-in-bashrc
[3] vmtouch:https://github.com/hoytech/vmtouch

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值