accidentally deleted /var/lib/apt/

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
10
down vote

favorite
1












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?










share|improve this question



























    up vote
    10
    down vote

    favorite
    1












    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?










    share|improve this question

























      up vote
      10
      down vote

      favorite
      1









      up vote
      10
      down vote

      favorite
      1






      1





      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?










      share|improve this question















      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?







      command-line apt files






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 10 at 2:27









      Sergiy Kolodyazhnyy

      69k9143303




      69k9143303










      asked Dec 9 at 7:59









      Hossein Hosseinvand

      5162712




      5162712




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          24
          down vote



          accepted










          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 via apt-add-repository ( and then there's also /etc/apt/trusted.gpg and /etc/apt/trusted.gpg.d/) and cdroms.list which should reference the installation media as source of packages. Removed /var/lib/apt/keyrings/ubuntu-archive-keyring.gpg may be reinstalled with sudo apt-get install --reinstall ubuntu-keyring.



          There's also /var/lib/apt/lists, which contains lock files for when apt 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 run apt-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 via apt-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.






          share|improve this answer


















          • 9




            You will also want to review how the error was made in the first place, because writing out sudo followed by rm -rf followed by an unintended directory name followed by * should not be something your brain allows to happen. Corrective action/changes to behaviours may be required to avoid much worse problems in the future.
            – Lightness Races in Orbit
            Dec 10 at 1:56






          • 1




            @LightnessRacesinOrbit I think this comment should be placed under OP's question, but I do agree - user has to know what they type and avoid doing rm -rf without checking and ensuring that they remove the right thing first.
            – Sergiy Kolodyazhnyy
            Dec 10 at 1:58






          • 1




            Well I think it should be added to the answer is why I put it here :) Comments under the question should be for suggesting clarifications to the question
            – Lightness Races in Orbit
            Dec 10 at 2:11






          • 1




            @KasperThystrupKarstensen Agreed. Often you can also see echo being prepended first to a command you intend to run with wildcard or other destructive commands. For example, echo rm /tmp/* type of thing
            – Sergiy Kolodyazhnyy
            Dec 10 at 9:30






          • 1




            That's spot on, thanks. Of course it's not like I've never made such a mistake, but I immediately reviewed the error and adjusted my practices, such that I never made it again :) It's a formative experience as long as you learn from it.
            – Lightness Races in Orbit
            Dec 10 at 10:31











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1099511%2faccidentally-deleted-var-lib-apt%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          24
          down vote



          accepted










          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 via apt-add-repository ( and then there's also /etc/apt/trusted.gpg and /etc/apt/trusted.gpg.d/) and cdroms.list which should reference the installation media as source of packages. Removed /var/lib/apt/keyrings/ubuntu-archive-keyring.gpg may be reinstalled with sudo apt-get install --reinstall ubuntu-keyring.



          There's also /var/lib/apt/lists, which contains lock files for when apt 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 run apt-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 via apt-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.






          share|improve this answer


















          • 9




            You will also want to review how the error was made in the first place, because writing out sudo followed by rm -rf followed by an unintended directory name followed by * should not be something your brain allows to happen. Corrective action/changes to behaviours may be required to avoid much worse problems in the future.
            – Lightness Races in Orbit
            Dec 10 at 1:56






          • 1




            @LightnessRacesinOrbit I think this comment should be placed under OP's question, but I do agree - user has to know what they type and avoid doing rm -rf without checking and ensuring that they remove the right thing first.
            – Sergiy Kolodyazhnyy
            Dec 10 at 1:58






          • 1




            Well I think it should be added to the answer is why I put it here :) Comments under the question should be for suggesting clarifications to the question
            – Lightness Races in Orbit
            Dec 10 at 2:11






          • 1




            @KasperThystrupKarstensen Agreed. Often you can also see echo being prepended first to a command you intend to run with wildcard or other destructive commands. For example, echo rm /tmp/* type of thing
            – Sergiy Kolodyazhnyy
            Dec 10 at 9:30






          • 1




            That's spot on, thanks. Of course it's not like I've never made such a mistake, but I immediately reviewed the error and adjusted my practices, such that I never made it again :) It's a formative experience as long as you learn from it.
            – Lightness Races in Orbit
            Dec 10 at 10:31















          up vote
          24
          down vote



          accepted










          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 via apt-add-repository ( and then there's also /etc/apt/trusted.gpg and /etc/apt/trusted.gpg.d/) and cdroms.list which should reference the installation media as source of packages. Removed /var/lib/apt/keyrings/ubuntu-archive-keyring.gpg may be reinstalled with sudo apt-get install --reinstall ubuntu-keyring.



          There's also /var/lib/apt/lists, which contains lock files for when apt 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 run apt-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 via apt-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.






          share|improve this answer


















          • 9




            You will also want to review how the error was made in the first place, because writing out sudo followed by rm -rf followed by an unintended directory name followed by * should not be something your brain allows to happen. Corrective action/changes to behaviours may be required to avoid much worse problems in the future.
            – Lightness Races in Orbit
            Dec 10 at 1:56






          • 1




            @LightnessRacesinOrbit I think this comment should be placed under OP's question, but I do agree - user has to know what they type and avoid doing rm -rf without checking and ensuring that they remove the right thing first.
            – Sergiy Kolodyazhnyy
            Dec 10 at 1:58






          • 1




            Well I think it should be added to the answer is why I put it here :) Comments under the question should be for suggesting clarifications to the question
            – Lightness Races in Orbit
            Dec 10 at 2:11






          • 1




            @KasperThystrupKarstensen Agreed. Often you can also see echo being prepended first to a command you intend to run with wildcard or other destructive commands. For example, echo rm /tmp/* type of thing
            – Sergiy Kolodyazhnyy
            Dec 10 at 9:30






          • 1




            That's spot on, thanks. Of course it's not like I've never made such a mistake, but I immediately reviewed the error and adjusted my practices, such that I never made it again :) It's a formative experience as long as you learn from it.
            – Lightness Races in Orbit
            Dec 10 at 10:31













          up vote
          24
          down vote



          accepted







          up vote
          24
          down vote



          accepted






          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 via apt-add-repository ( and then there's also /etc/apt/trusted.gpg and /etc/apt/trusted.gpg.d/) and cdroms.list which should reference the installation media as source of packages. Removed /var/lib/apt/keyrings/ubuntu-archive-keyring.gpg may be reinstalled with sudo apt-get install --reinstall ubuntu-keyring.



          There's also /var/lib/apt/lists, which contains lock files for when apt 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 run apt-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 via apt-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.






          share|improve this answer














          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 via apt-add-repository ( and then there's also /etc/apt/trusted.gpg and /etc/apt/trusted.gpg.d/) and cdroms.list which should reference the installation media as source of packages. Removed /var/lib/apt/keyrings/ubuntu-archive-keyring.gpg may be reinstalled with sudo apt-get install --reinstall ubuntu-keyring.



          There's also /var/lib/apt/lists, which contains lock files for when apt 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 run apt-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 via apt-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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 10 at 2:25

























          answered Dec 9 at 8:05









          Sergiy Kolodyazhnyy

          69k9143303




          69k9143303







          • 9




            You will also want to review how the error was made in the first place, because writing out sudo followed by rm -rf followed by an unintended directory name followed by * should not be something your brain allows to happen. Corrective action/changes to behaviours may be required to avoid much worse problems in the future.
            – Lightness Races in Orbit
            Dec 10 at 1:56






          • 1




            @LightnessRacesinOrbit I think this comment should be placed under OP's question, but I do agree - user has to know what they type and avoid doing rm -rf without checking and ensuring that they remove the right thing first.
            – Sergiy Kolodyazhnyy
            Dec 10 at 1:58






          • 1




            Well I think it should be added to the answer is why I put it here :) Comments under the question should be for suggesting clarifications to the question
            – Lightness Races in Orbit
            Dec 10 at 2:11






          • 1




            @KasperThystrupKarstensen Agreed. Often you can also see echo being prepended first to a command you intend to run with wildcard or other destructive commands. For example, echo rm /tmp/* type of thing
            – Sergiy Kolodyazhnyy
            Dec 10 at 9:30






          • 1




            That's spot on, thanks. Of course it's not like I've never made such a mistake, but I immediately reviewed the error and adjusted my practices, such that I never made it again :) It's a formative experience as long as you learn from it.
            – Lightness Races in Orbit
            Dec 10 at 10:31













          • 9




            You will also want to review how the error was made in the first place, because writing out sudo followed by rm -rf followed by an unintended directory name followed by * should not be something your brain allows to happen. Corrective action/changes to behaviours may be required to avoid much worse problems in the future.
            – Lightness Races in Orbit
            Dec 10 at 1:56






          • 1




            @LightnessRacesinOrbit I think this comment should be placed under OP's question, but I do agree - user has to know what they type and avoid doing rm -rf without checking and ensuring that they remove the right thing first.
            – Sergiy Kolodyazhnyy
            Dec 10 at 1:58






          • 1




            Well I think it should be added to the answer is why I put it here :) Comments under the question should be for suggesting clarifications to the question
            – Lightness Races in Orbit
            Dec 10 at 2:11






          • 1




            @KasperThystrupKarstensen Agreed. Often you can also see echo being prepended first to a command you intend to run with wildcard or other destructive commands. For example, echo rm /tmp/* type of thing
            – Sergiy Kolodyazhnyy
            Dec 10 at 9:30






          • 1




            That's spot on, thanks. Of course it's not like I've never made such a mistake, but I immediately reviewed the error and adjusted my practices, such that I never made it again :) It's a formative experience as long as you learn from it.
            – Lightness Races in Orbit
            Dec 10 at 10:31








          9




          9




          You will also want to review how the error was made in the first place, because writing out sudo followed by rm -rf followed by an unintended directory name followed by * should not be something your brain allows to happen. Corrective action/changes to behaviours may be required to avoid much worse problems in the future.
          – Lightness Races in Orbit
          Dec 10 at 1:56




          You will also want to review how the error was made in the first place, because writing out sudo followed by rm -rf followed by an unintended directory name followed by * should not be something your brain allows to happen. Corrective action/changes to behaviours may be required to avoid much worse problems in the future.
          – Lightness Races in Orbit
          Dec 10 at 1:56




          1




          1




          @LightnessRacesinOrbit I think this comment should be placed under OP's question, but I do agree - user has to know what they type and avoid doing rm -rf without checking and ensuring that they remove the right thing first.
          – Sergiy Kolodyazhnyy
          Dec 10 at 1:58




          @LightnessRacesinOrbit I think this comment should be placed under OP's question, but I do agree - user has to know what they type and avoid doing rm -rf without checking and ensuring that they remove the right thing first.
          – Sergiy Kolodyazhnyy
          Dec 10 at 1:58




          1




          1




          Well I think it should be added to the answer is why I put it here :) Comments under the question should be for suggesting clarifications to the question
          – Lightness Races in Orbit
          Dec 10 at 2:11




          Well I think it should be added to the answer is why I put it here :) Comments under the question should be for suggesting clarifications to the question
          – Lightness Races in Orbit
          Dec 10 at 2:11




          1




          1




          @KasperThystrupKarstensen Agreed. Often you can also see echo being prepended first to a command you intend to run with wildcard or other destructive commands. For example, echo rm /tmp/* type of thing
          – Sergiy Kolodyazhnyy
          Dec 10 at 9:30




          @KasperThystrupKarstensen Agreed. Often you can also see echo being prepended first to a command you intend to run with wildcard or other destructive commands. For example, echo rm /tmp/* type of thing
          – Sergiy Kolodyazhnyy
          Dec 10 at 9:30




          1




          1




          That's spot on, thanks. Of course it's not like I've never made such a mistake, but I immediately reviewed the error and adjusted my practices, such that I never made it again :) It's a formative experience as long as you learn from it.
          – Lightness Races in Orbit
          Dec 10 at 10:31





          That's spot on, thanks. Of course it's not like I've never made such a mistake, but I immediately reviewed the error and adjusted my practices, such that I never made it again :) It's a formative experience as long as you learn from it.
          – Lightness Races in Orbit
          Dec 10 at 10:31


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1099511%2faccidentally-deleted-var-lib-apt%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown






          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay