How to Undo apt-get remove?

Solution 1:

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.

Solution 2:

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

Solution 3:

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

Solution 4:

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.