Is it possible to undo an apt-get install command?
Basically, you'll have to both apt-get remove
(or apt-get purge) the package and run apt-get autoremove
after that, to have it revert the installation of package-one
.
Let's look at the whole process:
sudo apt-get install package-one
installs 50 dependencies with it marked "automatic" as also can be seen from the log excerpt in your questionsudo apt-get purge package-one
removes (purges) just one, but do run this!All following install actions (if you run any) will yield an informational message with the no longer needed packages:
The following packages were automatically installed and are no longer required: package-two package-three [...] Use 'apt-get autoremove' to remove them.
This list is basically just a list of all packages marked as "automatic" without a reverse dependency on them. In other words, there's no reason for them to be installed as far as the package management is concerned.
Note: No installation is needed! It's just to demonstrate that APT is smart to tell you about your unneeded packages!
sudo apt-get autoremove --purge
removes (purges) these
More information
Official documentation on
autoremove
from theapt-get(8)
manpage:autoremove
is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.What is the correct way to completely remove an application?
When you want to remove a package and its dependencies that installed at the time, you should use:
sudo apt-get purge package
sudo apt-get --purge autoremove
but to undo apt
actions, you can use apt-undo
script. It is a simple script that can undo the apt
actions performed in Ubuntu. It is to be noted that this script can only work if you use it instead of apt-get
to install/upgrade/remove/purge/downgrade your packages.
To install apt-undo
in Ubuntu, run the following commands in the terminal:
sudo add-apt-repository ppa:lkjoel/apt-undo
sudo apt-get update
sudo apt-get install apt-undo
usage:
apt-undo install yourpackages
apt-undo remove yourpackages
apt-undo purge yourpackages
apt-undo upgrade
apt-undo dist-upgrade
apt-undo install yourpackages=old.version
apt-undo install yourpackages=new.version
To undo, the above aptitude
actions run following commands in the terminal:
apt-undo undo
Use the power of Unix. Take the log file line that you have, and construct a command that will undo what apt did. For example:
$ echo 'Install: libdbusmenu-qt2:amd64 (0.9.2-0ubuntu1, automatic), python-packagekit:amd64 (0.7.2-4ubuntu3, automatic), cups-pk-helper:amd64 (0.2.1.2-1ubuntu0.1, automatic),'|perl -pe 's/ \(.*?\)//g; s/,//g; s/^Install: //'
libdbusmenu-qt2:amd64 python-packagekit:amd64 cups-pk-helper:amd64
So you can use this purge all packages you installed accidentally, given the appropriate line from your log file:
$ dpkg -P $(echo '(full log line here)' | perl -pe 's/ \(.*?\)//g; s/,//g; s/^Install: //')
(I've used perl
instead of sed
because sed
uses a type of regular expression which doesn't support non-greedy matches, which was the easiest way of constructing what I needed)