0

I am using ubuntu 18.04. When I try to run sudo apt-get update I am getting the following error. Can anybody try to help me solve this problem?

E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi

E: Sub-process returned an error code

Following this when I try to run sudo apt-get update It completed successfully .

1 Answers1

0

First try

sudo apt-get -f install

If this does not help you, then try the following.

Check which package causing the problem by this command.

sudo dpkg --audit

Then reinstall or reconfigure it.

MR. ROBOT
  • 136
  • 1
  • 3
  • 11
  • sudo apt-get -f install works fine but sudo dpkg --audit doesn't return anything to the terminal. – Samuel Mideksa May 07 '19 at 08:19
  • Did you try sudo apt update after sudo apt -f install? Still you cannot do sudo apt update normally? – MR. ROBOT May 07 '19 at 08:39
  • yes I tried sudo apt-get update after sudo apt-get -f install and it still can't update properly with the above error message. But sudo apt-get -f install works fine. – Samuel Mideksa May 07 '19 at 09:18
  • Tell me the result of this script on on a terminal if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then echo 'true'; else echo 'false'; fi And tell if you have /dev/null – MR. ROBOT May 07 '19 at 14:25
  • The above command prints false to the terminal. And there is no /dev/null in my home directory. – Samuel Mideksa May 08 '19 at 06:53
  • OK, then show me the result of ls -l /var/lib/command-not-found/ and tell me if you have /usr/lib/cnf-update-db – MR. ROBOT May 08 '19 at 07:08
  • ls -l /var/lib/command-not-found/ returns total 0 and cd /usr/lib/cnf-update-db and the command bash: cd: /usr/lib/cnf-update-db: Not a directory returns bash: cd: /usr/lib/cnf-update-db: Not a directory. – Samuel Mideksa May 08 '19 at 07:14
  • cnf-update-db is a file. So you can get to know if it exists or not by cat /usr/lib/cnf-update-db – MR. ROBOT May 08 '19 at 07:18
  • I asked something wrong. Tell me the result of ls -l /var/lib/ | grep 'command-not-found' not ls -l /var/lib/command-not-found/. Sorry. – MR. ROBOT May 08 '19 at 07:23
  • well it returns drwxr-xr-x 2 root root 4096 ኤፕረ 24 2018 command-not-found to the command line. – Samuel Mideksa May 08 '19 at 07:35
  • How about cat /usr/lib/cnf-update-db? It said that there is no file? – MR. ROBOT May 08 '19 at 07:37
  • Some python code is printed like this`!/usr/bin/python3 if name == "main": if "--debug" in sys.argv[1:]: logging.basicConfig(level=logging.DEBUG) elif "--verbose" in sys.argv[1:]: logging.basicConfig(level=logging.INFO)
    db = CommandNotFound.dbpath
    if not os.access(os.path.dirname(db), os.W_OK):
        print("datbase directory %s not writable" % db)
        sys.exit(0)
    
    command_files = glob.glob("/var/lib/apt/lists/*Commands-*")
    if len(command_files) > 0:
        col = DbCreator(command_files)
        col.create(db)`
    
    – Samuel Mideksa May 08 '19 at 08:31
  • You have the file. So do sudo chmod a+w /var/lib/command-not-found/ and sudo apt update. – MR. ROBOT May 08 '19 at 09:01
  • What does sudo chmod a+w /var/lib/command-not-found/ do? The same error E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi' E: Sub-process returned an error code is getting printed to the terminal. Do I have to delete the file /var/lib/command-not-found/ after changing mode? – Samuel Mideksa May 08 '19 at 09:54
  • It means you give permission to write to the directory. Can you try this one more time if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then echo 'true'; else echo 'false';fi ? if the answer is yes, it means you need to make the file /dev/null manually by touch /dev/null. And then try sudo apt update again. – MR. ROBOT May 08 '19 at 10:01
  • The first command returns true. The second goes fine but the apt-get update is not working due to some issues. – Samuel Mideksa May 08 '19 at 10:28
  • Due to the same error? – MR. ROBOT May 08 '19 at 10:44
  • sorry I mean due to same error – Samuel Mideksa May 08 '19 at 11:30
  • To make it sure do if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi on a terminal please. If there is no error during it, it means a error exists somewhere else. – MR. ROBOT May 08 '19 at 11:34
  • The command that you just wrote raises an error bash: /usr/lib/cnf-update-db: /usr/bin/python3: bad interpreter: No such file or directory – Samuel Mideksa May 08 '19 at 11:40
  • It is giving me the error bash: /usr/lib/cnf-update-db: /usr/bin/python3: bad interpreter: No such file or directory – Samuel Mideksa May 08 '19 at 12:33
  • OK, then we understand that you need python3. Try sudo apt install python3 – MR. ROBOT May 08 '19 at 12:54
  • sudo apt-get install python3 works without an error. but when I type python3 --version It is raising the above error bash: /usr/lib/command-not-found: /usr/bin/python3: bad interpreter: No such file or directory – Samuel Mideksa May 09 '19 at 07:09
  • I have previously installed Anaconda and removed it from by removing the whole directory using sudo rm ~/Anaconda3 and removed the line invoking conda in .bashrc file. Was that causing the problem? – Samuel Mideksa May 09 '19 at 07:11
  • Probably yes. So you need to remove python3 completely first by sudo apt remove --purge python3 and then reinstall it by sudo apt install python3. I hope this solve the problem. – MR. ROBOT May 09 '19 at 07:22
  • It gives the following when I try to install python3 again after removing with purge E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). The purge also didn't succeed with the following errorE: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). ` – Samuel Mideksa May 09 '19 at 07:26
  • Then please try sudo apt --fix-broken install – MR. ROBOT May 09 '19 at 07:27
  • I tried this one sudo apt --fix-broken install python3 but it is not working E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). – Samuel Mideksa May 09 '19 at 07:30
  • Please check what is wrong by sudo apt-get check – MR. ROBOT May 09 '19 at 11:03
  • Comments are not for extended discussion; this conversation has been moved to chat. – Seth May 09 '19 at 16:44