I accidentally deleted content of /var/lib/apt with command below:
sudo rm -rf /var/lib/apt/*
what should I do now? can I restore it? is it necessary?
I accidentally deleted content of /var/lib/apt with command below:
sudo rm -rf /var/lib/apt/*
what should I do now? can I restore it? is it necessary?
The folder contains a few interesting things, in particular there is
/var/lib/apt/keyrings/
directory for any repositories that you've added to the system viaapt-add-repository
( and then there's also/etc/apt/trusted.gpg
and/etc/apt/trusted.gpg.d/
) andcdroms.list
which should reference the installation media as source of packages. Removed/var/lib/apt/keyrings/ubuntu-archive-keyring.gpg
may be reinstalled withsudo apt-get install --reinstall ubuntu-keyring
.There's also
/var/lib/apt/lists
, which contains lock files for whenapt
is running update or upgrade, and lists of packages in remote repositories. Items in that directory sometimes are cleared or deleted as in this post for example. It should regenerate once you runapt-get update
.In short, I wouldn't worry about this much. Just run
sudo apt-get update
and it should be back, however if you have added repositories viaapt-add-repository
which may have required a GPG key, then you may want to add that key again or temporarily remove that repository from/etc/apt/sources.list.d
.Although it's not a huge issue in this case, as Lightness mentioned in the comments, the core of the issue is the accidental use of
rm -rf
. A user should realize full responsibility when they wield commands which can do damage to their system. There's countless examples on AskUbuntu and other StackExchange sites where users delete or change ownership of the core system components. From the point of view of new users it can be understandable that new users are not familiar with how much damage can be done, although that does not free the new user of the responsibility. There's no point in condemning either the command or the user, but the right way should be developing habits of verifying your own steps in command-line or elsewhere. This does not just apply to Ubuntu but computing in general, and comes with experience and often through actually making the mistakes and breaking your system only to repair it and break again. One has to be at peace with the fact that you are in control of the system and with the responsibility that comes from mistakes, and that often you'll learn a thing or two from breaking and fixing things.