Apt hangs because of command-not-found

Asked by Mustafa ├ľncel on 2021-04-28

This happens to me frequently. I'm using Ubuntu 21.04 Hirsute Hippo with GNOME DE. I have some PPAs added but the cause is command-not-found, confirmed both from stack trace, the fact that this problem immediately going away after uninstalling command-not-found, and that others experiencing the issue on the internet.

Here is the stack trace:

Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 26, in <module>
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 94, in create
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 138, in _fill_commands
    self._parse_single_commands_file(con, fp)
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 223, in _parse_single_commands_file
    pkg_id = self._insert_package(con, pkgname, version, component, priority)
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 161, in _insert_package

I tried restarting my computer like 3 times. I do not have any hibernation or something set-up. I tried these when no applications are open on a fresh boot.

I tried disabling the some of last PPAs before it hangs but it did not solve, and after uninstalling, apt update'ing, it succeeded without any hang or freeze. After that I reinstalled it (because I don't know what does this package do and it was installed with system so I don't want to remove it) but after trying apt update after installing, it started to hang again. Basically it hangs with command-not-found, but not without it so it must not be the PPAs causing it. My internet is also on good speed and my computer specs are good too, this must be a deadlock in program or something?

I waited for like 10-15 minutes, I can wait more but if this happens because I have many packages (I did not install much packages but neofetch shows something like 2000+, not sure if they are pre-installed ones or just dependencies of the packages I installed), it should happen all the time right? It only happens sometimes and when it happens it persists after restarts and only fixes itself randomly or such, don't know. This frustrates me so I want this to be fixed ASAP or can someone confirm that removing this package is completely safe and will not cause any side-effects?

Just read the main page and this package is for, well, the messages about command not found, like this? "command not found, but can be installed with: apt install <package>, or snap <..> something # version ..x.."? If that messages come from this package, I would like to keep it as sometimes it saves me some time from searching on browser what command belongs to what package and how can I install the newest version (i.e. snap version vs apt version, they can be different - for Gradle example, one is 4.x and one is 6.x, two major versions!), but those hangs definitely take more time than those.

I may also want to remove fwupdmgr and packagekitd since they cause issues like these too, fwupdmgr can't find any updates on my machine but it sometimes causes lvfs errors in Ubuntu Software Center. Packagekitd also causes hangs on updater sometimes, saying waiting for packagekitd to exit. However that can be easily fixed by entering "sudo systemctl stop packagekitd". I'm just saying these because I'm checking updates regularly and those things frustrates me. I know this only for asking questions about command-not-found and not other packages but I'm just talking about my frustration after all 3 packages combine and make my update checking process a nightmare.

I tried sudo aptitude purge ~c command-not-found as suggested somewhere else but that tried to remove some packages which I use along with command-not-found, are they depend on command-not-found or such? I denied that prompt to not uninstall those packages and just did sudo aptitude purge command-not-found, doing update and reinstalling it afterwards (issue persists though).

Question information

English Edit question
Ubuntu command-not-found Edit question
No assignee Edit question
Last query:
Last reply:

What is the full output of:

sudo apt update
sudo apt upgrade


Launchpad Janitor (janitor) said : #2

This question was expired because it remained in the 'Needs information' state without activity for the last 15 days.