I wanted a fresh install of Python and ran sudo apt-get remove --purge python. Apparently it has killed almost everything I had installed in my system.

Looking at the history.log I guess I could manually install the packages again, but there are hundreds of them, I can't just copy paste.

Ironically, python is still installed. Could I perform some replace regex with it so I can fix this mess? Or with bash.

  • 1
    If apt is still working: sudo apt-get install ubuntu-desktop. – muru Sep 11 '14 at 9:02
  • @muru thanks, now 140 MB are being installed. However the purge removed around 350. – dabadaba Sep 11 '14 at 9:03
  • @muru well now I am not sure, if downloaded or installed. But I still have some packages missing, ubuntu-desktop just helped me get back some of it (which is a lot, thanks). – dabadaba Sep 11 '14 at 9:09
  • 1
    @muru nvm, I managed to make my own python script and it's already installing the missing packages. Installign ubuntu-desktop package helped a lot though, thanks! – dabadaba Sep 11 '14 at 9:18

First I ran sudo apt-get install ubuntu-desktop as I was told in the comments, then I copied the part of /var/log/apt/history.log concerning the purge action, and ran on it the following python script I made. Probably someone more skilled in regex would cry when seeing how I did it, but it worked for me:

import re

f = open('remove.log', 'r')
s = ""
for i in f:
    s += i + '\n'

s = re.sub(':.*?', '', s)
s = re.sub(r'\([^)]*\)', '', s)
s = re.sub(',', '', s)
s = re.sub('amd64', '', s)

f = open('replaced.txt', 'w')

Then I could see a Install block and Purge block in replaced.txt, so I would just sudo apt-get install all the packages in the first block, and then in the second.

And voilà, apparently.

| improve this answer | |

I had a similar problem. @dabadaba's script worked great, but I found manually installing each package to be a little tedious.

Here is a python script I wrote to automate installing the packages listed in the replaced.txt file created in @dabadaba's answer

import subprocess

f = open('replaced.txt', 'r')

for line in f:
    if line.startswith('Install') or line.startswith('Purge'):
        packages = line.split()
        for i in range(1, len(packages)):
            print 'Do you want to install ' + packages[i] + '? [y/n]'
            input = raw_input()
            if input == 'y':
                print 'beginning install'
                p = subprocess.Popen('apt-get install ' + packages[i], shell=True)
                print 'not installing'
| improve this answer | |

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.