7

I was trying to delete the sources.list file for apt. After deleting, instead of issuing cd /etc/apt, I did sudo rm - r /etc/apt and now I've deleted it. I tried creating the /etc/apt directory again and running:

$ sudo apt-get update && apt-get upgrade 

This returns an error message as follows:

apt-get: relocation error: /usr/lib/x86_64-linux-gnu/libapt-private.so.0.0: symbol _ZTI17pkgAcquireStatus2, version APTPKG_5.0 not defined in file libapt-pkg.so.5.0 with link time reference

How do I restore my /etc/apt directory and fix apt?

  • 6
    /etc/apt should be a directory; sudo rm /etc/apt therefor shouldn't actually do anything other than print an error message. – derobert Feb 26 '18 at 17:11
  • Is this Debian, Ubuntu or Mint? You've tagged all three. – roaima Feb 26 '18 at 21:45
  • @derobert sorry I used rm -r – void Feb 27 '18 at 15:10
  • Ok — something else is also wrong with the system, as not having /etc/apt results in no errors, but some warnings like W: Unable to read /etc/apt/apt.conf.d/ - DirectoryExists (2: No such file or directory) (at least on Buster). I think the suggestion of reinstalling apt is a good place to start... – derobert Feb 27 '18 at 16:59
  • BTW: When you mistakenly sudo rm -r /etc/apt, were you trying to fix some other problem? – derobert Feb 27 '18 at 17:05
11

Issue at Hand

You report that you have deleted /etc/apt while attempting to delete your sources.list file. Now you experience errors when attempting to use apt.

I have referenced this post. Perhaps it can help you?

Solution

First, see if you still have a copy of apt's .deb file.

cd /var/cache/apt/archives

Now look for a .deb with apt in its name, if you are running Debian Stretch on a 64-bit system it should be apt_1.4.8_amd64.deb. Use tab to autocomplete, or if not found you can download apt and its dependencies here.

After you have located the necessary package run as root(sudo) the following command:

dpkg -i apt_1.4.8_amd64.deb

This should reinstall the apt for you. You should now be able to run sudo apt-get update && apt-get upgrade as expected. Remember if you need to recreate your sources.list file you should follow this example.

The error about missing /usr/lib/x86_64-linux-gnu/libapt-private.so.0.0 should be solved if not you can install the lib from here.

Then you need to copy the library file into /usr/lib and run this command as root(sudo):

ldconfig -n -v /usr/lib

This post may help too.

Conclusion

Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.

Best of Luck!

  • Thanks for the answer I haven't yet tried it out! I'll update! – void Feb 28 '18 at 4:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.