18

I know it is funny situation but i removed python with all associated programs from Ubuntu using sudo apt-get remove python? Obviously i can install back python, but it will take me a lot of time to install all programs that i removed. Maybe there is some solution?

Thanks

  • Please include research effort to remove down vote. – Colyn1337 Nov 21 '14 at 15:33
  • Wow! A 3 year old question, that's helping to restore my computer. So glad this was here and found on the google. Thanks! – Michael Cole Apr 30 '15 at 11:32
26

There is not an easy way but if you look at /var/log/apt/history.log you can see what was removed. Just reinstall each package that was removed.

  • 2
    It just saved my life! – Sanket Sahu May 24 '13 at 13:21
  • 3
    I registered with serverfault just to upvote this, thanks. – Phil Dec 9 '15 at 10:53
20

I just did this mistake, you can run the below commands to undo the remove of packages This will extract the information of the removed packages from the log file and reinstall them

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
  • lifesaver... should've realised apt remove libboost* was a bad idea – Persistence Feb 24 '18 at 2:38
  • 2
    Thanks, you saved my life!! Reminder: NEVER RUN "sudo apt purge python2.7" – user477152 Jul 9 '18 at 9:49
  • 2
    Don't run sudo apt remove python3 haha – ThaJay Sep 6 '18 at 15:33
  • Well, I used apt purge so rip me, good thing it was a fresh install. Would be nice to know that key (for most people) OS systems, like netplan, require this. Sure it references it in the remove list, before asking if you're sure, but who has time to look and be sure when it's easier just to smack the y key and return your system into oblivion... – DeeJayh May 4 at 17:52
5

I found a cool trick from the Ubuntu forums.

It is possible to run the following in a terminal:

awk '!/^Start|^Commandl|^End|^Upgrade:|^Error:/ { gsub( /\([^()]*\)/ ,"" );gsub(/ ,/," ");sub(/^Install:/,""); print}' /var/log/apt/history.log

Look at the output, then use

sudo apt-get install [packages]

and replace [packages] with the last line of packages that was returned (note that it may wrap).

  • You saved my day. It is really really helped me. – Khamidulla Aug 17 '18 at 19:45
1

Look up all the packages that got uninstalled. It is stored at /var/log/apt/history.log . You can write a shell program to install each package that was removed. Write it on any text editor GNU Emacs, vi, GNU Nano. Execute it through the terminal. All the programs that got uninstalled will get re-installed by themselves.

0

To add to ablackhat's answer, you can copy and paste everything after the last remove command in /var/log/apt/history.log into a new programmers editor. Regex replace :.*?, with (empty string), and copy all the resulting space-separated packages. Then run $ sudo apt-get install <paste>

0

Upgrading restores most of it, the rest.. you can use the techniques shown above. To upgrade just type "sudo apt-get upgrade"

  • why should apt-get upgrade reinstall packages that have been purposefully removed? – Gerald Schneider Jun 16 '17 at 10:11
  • It's actually not that far off from a perfect answer to the OP: wait three years and do apt-get dist-upgrade – quadruplebucky Jun 16 '17 at 10:36
-1

if you

 apt-get install python

Python will be reinstalled with all of its prerequisites which is what I'm assuming was all the associated programs your speaking about?

  • I have already installed Python, but programs which where dependent on it like Zim, GImp and a lot of others wasn't reverted(( Even Gedit isn't working – IgorDiy Apr 18 '12 at 20:11
  • -1. Doesn't resolve the OP's question in that everything that needs Python got removed also. – Magellan Apr 19 '12 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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