Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I ran by mistake apt-get remove WRONG_PACKAGE, after realizing this, I pressed CTRL+Z to break the process since removing that package started removing around 100+ other packages.

Now when I try to run apt-get install REMOVED_ONES it states:

E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

Is there any way to revert it?

share|improve this question
    
Did you run 'sudo dpkg --configure -a' ? if yes, post its output too. –  Akash Shende Jan 4 '13 at 18:00
    
Added an answer that should cover a locking problem, the suspend state of a process and a explanation of what happened there. –  Luis Jan 4 '13 at 18:08
    
No Akash, I didn't run that command. By mistake I pressed enter instead of N when I wanted to uninstall libjpgeg or something like that (to recompile it manually as I needed a newer version in order to compile something). –  Sorin Trimbitas Jan 4 '13 at 21:10

2 Answers 2

up vote 10 down vote accepted

Actually...

CTRL+Z will suspend the process.

CTRL+c will kill the process.

Note that suspending a process will send it to the background until you call it again. Since it is suspended you can run another program. It will "look" like is gone but is not. It will actually tell you the Process ID that has been assigned to it before going to the background.

To call the process again (Actually to continue the process where you left it) type fg.

fg means ForeGround. To bring to foreground from background if you want to have an idea of it. If you happen to have other suspended process, you can go to them by doing fg 1 for process 1, fg 2 for process 2 and so on.

The difference when applied to apt-get (Or aptitude or any other package manager) is that the lock files will not get erased when doing a remove/upgrade/install or that the repo file might get corrupted.

You will need to literally remove the files with rm.

Before removing anything try what the package manager suggests, in that case:

sudo dpkg --configure -a or sudo dpkg-reconfigure -a in case you did an upgrade. In most cases (in ALL cases for me) I had to first delete the lock files as followed:

sudo rm -fr /var/cache/apt/archives/lock
sudo rm -fr /var/lib/dpkg/lock

If by chance you want to remove the process (if it is still active) you can either look it up by using ps -e and finding the PID numer, then using kill -9 PID where PID is the number you found or issuing sudo killall NAME_OF_PROCESS

Alternative you can also do:

sudo fuser -cuk /var/lib/dpkg/lock
sudo fuser -cuk /var/cache/apt/archives/lock
sudo rm -fr /var/cache/apt/archives/lock
sudo rm -fr /var/lib/dpkg/lock

After all of this you can either use the commands recommended by the app as I mentioned in the beginning or simply try to reinstall the package you mistakenly removed. I also recommend doing an sudo apt-get update just to make sure everything is correct.

Note that if the package removed all of those other packages, try first to install said package. For example if you did:

sudo apt-get remove unity by mistake, then first try to do the steps I mentioned and then install that precise package again:

sudo apt-get install unity.

If by chance it did not get uninstall then do:

sudo -apt-get install --reinstall unity

share|improve this answer
1  
Great answer. You've mentioned killing apt-get, this reminds me of a friend of mine who disconnected his computer's power while apt-get was doing a dist-upgrade :) Heavy stuff. –  Rafał Cieślak Jan 4 '13 at 18:12
    
@rafalcieslak Wow that happened to me but this time the power went off in the entire block and I was like 75% doing the upgrade. –  Luis Jan 4 '13 at 18:16
    
Thank you Luis! That solved the issue, after 20 minutes the system is back ok :D ( I was lucky to save the console in a separate file to see which packages were removed in the first place ) –  Sorin Trimbitas Jan 4 '13 at 21:13
    
Glad to help @SorinTrimbitas –  Luis Jan 4 '13 at 21:29

I had a similar issue once and ran the command as suggested. After you do that you can apt-get install WRONG_PACKAGE. It should reinstall all the packages it tried to remove. You do not need to install each one manually.

share|improve this answer

Your Answer

 
discard

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.