Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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
up vote 17 down vote accepted

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.

share|improve this answer
It just saved my life! – Kumar Sanket Sahu May 24 '13 at 13:21
I registered with serverfault just to upvote this, thanks. – Phil Dec 9 '15 at 10:53

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 packaged 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 
share|improve this answer

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).

share|improve this answer

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.

share|improve this answer

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>

share|improve this answer

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?

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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