9
sudo apt-get install vlc
Reading package lists... Error!
E: flAbsPath on /var/lib/dpkg/status failed - realpath (2: No such file or directory)
E: Could not open file  - open (2: No such file or directory)
E: Problem opening 
E: The package lists or status file could not be parsed or opened.

Whenever I try to install any software I get this error. How do I solve this ?

1

5 Answers 5

15

I faced a similar issue recently with ubuntu 16.04.3 LTS, what worked for me is as following -

First you need to create an empty file, as following :-

adminuser@sandbox:~$ sudo touch /var/lib/dpkg/status

Now run update & upgrade :-

adminuser@sandbox:~$ sudo apt update && sudo apt upgrade

Probable you may end up seeing something like this --

adminuser@sandbox:~$ sudo apt update
Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
All packages are up to date.

adminuser@sandbox:~$ apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

But if you logout and login back, your MOTD will show you that some updates are pending -

Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-96-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

108 packages can be updated.
27 updates are security updates.

At this point, you need to run dist-upgrade -

adminuser@sandbox:~$ sudo apt dist-upgrade

This should fix the issue, but make sure it shouldn't push you ahead to actually upgrade the Ubuntu to a new version. As well as I understand, until the launch of Ubuntu 18.04 LTS this should work. Good Luck

1
  • This worked for me. thank you. Commented Nov 12, 2020 at 10:49
9

Step 1: cd /

Step 2: cd var/lib/

Step 3: mkdir dpkg

Step 4: touch status

This worked for me. :)

2
  • 1
    This solution works for me. I accidentally remove dpkg directory.
    – user968333
    Commented Aug 23, 2019 at 13:52
  • I had a broken build and had to run fsck to fix it. In the process that must have removed the dpkg folder - this was my chosen solve.
    – alanionita
    Commented Jun 20, 2021 at 21:33
3
sudo mkdir -p /var/lib/dpkg/{alternatives,info,parts,triggers,updates}

Still you need to copy this file

sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status

apt-get download dpkg
sudo dpkg -i dpkg*.deb
apt-get download base-files
sudo dpkg -i base-files*.deb
sudo apt-get update
sudo apt-get check
1

My /var/lib/dpkg/status file got deleted and according to apt I had no packages installed, as it determines them from the status file. I used the following method to regenerate the /var/lib/dpkg/status file. The method worked very fine for me in Kali GNU/Linux, which is Debian-based.

NOTE:

  • This method assumes that all installed packages have created entries in the /usr/share/doc directory.

  • This method starts from an empty /var/lib/dpkg/status file.

  • This method may not work if you have more than 1 repository providing the same package. If you do have more than 1 repository providing the same package, temporarily disable the subsidiary repo, then delete the package cache lists for the repo in /var/lib/apt/lists/.

  1. Delete the current status and status-old files. Make a backup of the files before deletion incase you get errors.

    mkdir ~/dpkg-status-backup
    cp /var/lib/dpkg/{status,status-old} ~/dpkg-status-backup
    rm /var/lib/dpkg/{status,status-old}
    
  2. Get list of all packages installed, one package per line.  Note: it's 1 (one) not l (lower-case L).

    ls -1 /usr/share/doc > installed-packages.list
    
  3. Rewrite the packages list into one line.

    tr '\n' ' ' < installed-packages.list > installed-packages-one-line.list
    
  4. Create an empty status file to enable apt-cache to run.

    touch /var/lib/dpkg/status
    
  5. Generate package records using apt-cache.

    cat installed-packages-one-line.list | xargs apt-cache show > raw-status-file
    
  6. The raw-status-file may contain Status: fields for some packages. Delete them to avoid duplication.

    sed -i '/^Status:/d' raw-status-file
    
  7. Add the Status: field for every package to indicate to apt & dpkg that they're installed.

    sed -i 's/^Package:.*/&\nStatus: install ok installed/' raw-status-file
    
  8. Remove fields unwanted by dpkg in status file: SHA1:, SHA256:, MD5sum:, Description-md5:, Size: & Filename: .

    sed -i '/^MD5sum:/d' raw-status-file
    sed -i '/^SHA1:/d' raw-status-file
    sed -i '/^SHA256:/d' raw-status-file
    sed -i '/^Size:/d' raw-status-file
    sed -i '/^Filename:/d' raw-status-file
    sed -i '/^Description-md5:/d' raw-status-file
    
  9. The resultant raw-status-file after running the above commands is now the actual dpkg status file.

    mv raw-status-file status
    
  10. Copy the status file to /var/lib/dpkg/ as status and status-old.

    cp status /var/lib/dpkg/status
    cp status /var/lib/dpkg/status-old
    
  11. Now run dpkg to validate your new status file. If you get errors, take hints from dpkg's error report, & solve accordingly. If you get no errors, then the status file has the correct syntax.

    dpkg --get-selections
    
  12. Re-enable the disabled repos then run apt to update package cache lists to prevent the error packages have unmet dependencies.

    apt update
    
  13. If you run into packages have unmet dependencies error in apt, then make sure you've enabled the subsidiary repos that provide the dependencies, then run aptitude. I prefer aptitude because it's better at solving package installation errors.

    aptitude full-upgrade
    

If you get no errors/your errors have been resolved from apt or dpkg, and get "PACKAGE is already the newest version..." when you try to install a program you're sure is already installed, such as coreutils, then you've successfully regenerated the dpkg status file.

Clean-up the temp files created and the backup.

rm installed-packages.list installed-packages-one-line.list status
rm -r ~/dpkg-status-backup
0

You have to recreate a /var/lib/dpkg file structure, which does require backups or luck (and maybe both). See here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .