Score:3

debconf: apt-extracttemplates failed: No such file or directory

ug flag

I was running the command sudo apt install mongodb-org. And I got these errors.

E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 31%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 63%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 94%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 100%
dpkg: error: unable to create new file '/var/lib/dpkg/info/format-new': No such 
file or directory
E: Sub-process /usr/bin/dpkg returned an error code (2)

I am using Ubuntu 20.04.

Output of ls -ls /var/lib/dpkg/info/{,format-new} | head -n2

ls: cannot access '/var/lib/dpkg/info/': No such file or directory
ls: cannot access '/var/lib/dpkg/info/format-new': No such file or directory

Output of apt-cache policy debconf

debconf:
  Installed: (none)
  Candidate: 1.5.73
  Version table:
     1.5.73 500
        500 http://in.archive.ubuntu.com/ubuntu focal/main amd64 Packages
N0rbert avatar
zw flag
Please add output of `ls -ls /var/lib/dpkg/info/{,format-new} | head -n2` and `apt-cache policy debconf` to the question.
Raman  avatar
ug flag
@N0rbert I have added the outputs. Please check it.
Score:2
zw flag

You have severe damage of your system. Below is the possible way to fix this situation on low level:

# create missed dpkg info directory
sudo mkdir /var/lib/dpkg/info/

# create missed dpkg alternatives directory
sudo mkdir /var/lib/dpkg/alternatives

# recreate other directories as well
sudo mkdir /var/lib/dpkg/{parts,triggers,updates}

# update package lists
sudo apt-get update

# install missed debconf package
sudo apt-get install debconf

# reinstall all currently installed packages to correctly fill /var/lib/dpkg/info/
sudo apt-get install --reinstall $(dpkg -l | grep ^ii | awk '{print $2}')

And finally install whatever packages with commands like:

sudo apt-get dist-upgrade
sudo apt-get install mongodb-org
Raman  avatar
ug flag
while doing these process, I got new error - update-alternatives: error: cannot scan directory '/var/lib/dpkg/alternatives': No such file or directory
N0rbert avatar
zw flag
Then run `sudo mkdir /var/lib/dpkg/alternatives` and repeat steps in answer.
Raman  avatar
ug flag
Finally, it worked. Thankyou so much Sir :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.