Packages are removed when I use "apt-get install" with a hyphen after the package name [duplicate]

In an attempt to install cuda, I copy-pasted some apt-get install packages. For unknown reasons the line that I got run in the end is the following:

sudo apt-get install libgtk2.0-

The result was that many packages got removed. Randomly picking a few:

libreoffice-*
python-*
xfce4-* 

The list is huge. A considerable number of system parts have been uninstalled. Now this seems like a serious deviation from what I expect when I run apt-get install.

What is going on?


Solution 1:

The problem is the following (from man apt-get):

install

install is followed by one or more packages desired for installation or upgrading. Each package is a package name, not a fully qualified filename (for instance, in a Debian system, apt-utils would be the argument provided, not apt-utils_0.9.12.1_amd64.deb). All packages required by the package(s) specified for installation will also be retrieved and installed. The /etc/apt/sources.list file is used to locate the desired packages. If a hyphen is appended to the package name (with no intervening space), the identified package will be removed if it is installed. Similarly a plus sign can be used to designate a package to install. These latter features may be used to override decisions made by apt-get's conflict resolution system.

So, adding a hyphen to the end of a package name means "remove that package". Specifically, in your case, it would remove these:

Note, selecting 'libgtk2.0-doc' for regex 'libgtk2.0'
Note, selecting 'libgtk2.0-cil' for regex 'libgtk2.0'
Note, selecting 'libgtk2.0-bin' for regex 'libgtk2.0'
Note, selecting 'libgtk2.0-common' for regex 'libgtk2.0'
Note, selecting 'libgtk2.0-0' for regex 'libgtk2.0'
Note, selecting 'libgtk2.0-cil-dev' for regex 'libgtk2.0'
Note, selecting 'libgtk2.0-0-dbg' for regex 'libgtk2.0'
Note, selecting 'libgtk2.0-dev' for regex 'libgtk2.0'

In other words, you removed the entire gtk2 library set, and a lot of programs depend on gtk2. As a result, a lot of programs were removed.

So, no, this is not a bug. It is, admittedly, surprising behavior if you don't know about it but it is documented and intended.

Solution 2:

Take a look in /var/log/apt/history.log to see what exactly has been removed. Then, just reinstall these packages.