15

I just walked into the trap of calling

sudo apt-get install autoremove

I did it because I was unable to install sudo apt-get install libopencv-dev because of unmet dependencies. Now my ros-indigo installation is broke, opencv is still not installed and I also cannot reinstall it.

When trying to install it I get only

E: Unable to correct problems, you have held broken packages.

I fear that I'm really close to killing my entire package-dependency system. Can someone help me please?

Can I somehow use the file /var/log/apt to reverse the step of deleting ros?

mcExchange
  • 3,088

2 Answers2

18

I don't Know if there is any simpler way but if you look at /var/log/apt/history.log you can see what was removed. Just reinstall each package that was removed.

Using this may save your time

echo '#!/bin/bash' > restore
echo sudo apt-get install `grep Remove /var/log/apt/history.log | tail -1 | sed -e 's|Remove: ||g' -e 's|([^)]*)||g' -e 's|:[^ ]* ||g' -e 's|,||g'` >> restore
chmod +x restore 
./restore
storm
  • 4,973
  • this is a giant list of the form Commandline: apt-get autoremove Remove: ros-indigo-tf:amd64 (1.11.7-0trusty-20160111-112853-0800), ros-indigo-xacro:amd64 (1.9.5-0trusty-20160110-105433-0800), ... and so on (ca 1000 entries). Rewriting everything in the form sudo apt-get install ros-indigo-tf:amd64 ros-indigo-xacro:amd64 ... can become very tedious. Isn't there an automatic command to install them ? – mcExchange Feb 25 '16 at 14:57
  • 1
    Also the error E: Unable to correct problems, you have held broken packages. troubles me. Can I find out where it exactly comes from (which package) ? – mcExchange Feb 25 '16 at 15:00
  • answer was edited – storm Feb 25 '16 at 15:02
  • Thanks, but there is still something broke :(. Package libswresample0 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'libswresample0' has no installation candidate – mcExchange Feb 25 '16 at 15:07
  • Commenting here so I don't lose this. +1 Can't tell you how many times I have ran autoremove and it removed something I needed to keep. This was very simple to run and worked flawless. Thank you! – Terrance Jul 06 '17 at 23:21
  • This was the first time autoremove actually removed something useful and my computer became useless. Your solution solved my problem. Thank you. – Muhammad bin Yusrat Dec 15 '17 at 17:56
  • This is gold! Thanks for saving me a bunch of time. autoremove nuked my python environments. – Rafay Khan May 28 '20 at 07:27
  • Just needed a reboot after running the OPs command – Rafay Khan May 28 '20 at 07:37
0

If you are using ROS and the other answer does not fix the problem completely, you can go to your workspace and do:

rosdep install --from-paths src --ignore-src -r -y
Nesi
  • 1