1

After upgrading a machine from 17.10 to 18.04LTS, the previously happy installation of Wine appears to be borked. Given the many issues reported (and the interesting comments from Clem on Linux Mint discoveries), I thought I would just blow away the old Wine, and reinstall from scratch following the "canonical" instructions here on Askubuntu.

Unfortunately, I don't get very far. In response to

sudo apt purge wine*

I get the error message:

[sudo] password for user: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package winehq.key
E: Couldn't find any package by glob 'winehq.key'
E: Couldn't find any package by regex 'winehq.key'

Yet, for which wine I get /usr/bin/wine, and dpkg gives me this:

$ dpkg -l | grep wine
ii  fonts-wine              3.0-1ubuntu1  all          Windows API implementation - fonts
ii  libwine:amd64           3.0-1ubuntu1  amd64        Windows API implementation - library
ii  wine-stable             3.0-1ubuntu1  all          Windows API implementation - standard suite
ii  wine-stable-amd64       4.0.1~bionic  amd64        WINE Is Not An Emulator - runs MS Windows programs
ii  wine64                  3.0-1ubuntu1  amd64        Windows API implementation - 64-bit binary loader
ii  winetricks              0.0+20180217-1all          package manager for Wine to install software easily

I really don't know what to do next. I've done all the searching I can think of on my error messages, but am none the wiser. And I don't feel I should proceed with a fresh Wine installation until I've obliterated the current (borked!) one.

How can I get rid of this Wine, then? If there are any other diagnostics I should/could run, please let me know and I'll update this question.

Dɑvïd
  • 1,936
  • 4
  • 24
  • 53
  • Is file winehq.key present in the current directory? Try escaping or quoting the asterisk character with sudo apt purge 'wine*' – user000001 Jun 02 '19 at 21:48
  • 1
    @user000001 Bizarrely enough, that worked! If you could turn your comment into an answer -- and best if you include a brief explanation as to why that would work! -- I'll give you an upvote and accept your answer. Thanks! – Dɑvïd Jun 03 '19 at 17:11

1 Answers1

3

The reason that it didn't work is that there was a file in the current directory that matched the pattern you tried to pass to apt.

When bash sees an (unquoted and unescaped) asterisk, question mark or other glob character in the command line, it checks the files in the current directory, and if any of the match the pattern, the word containing the special characters is replaced by a space separated list of the matching files. You can see this in your terminal if you type

echo *

where a list of the files/directories under current directory will be printed. In your case the pattern wine* matched the file winehq.key that was located in the current directory, so your command was transformed to

sudo apt purge winehq.key

which of course resulted in an error message since there are no packages with that name in the repository.

In this case, we want the glob pattern not to be interpreted by bash, but to be passed on literally to apt. This is done by escaping or quoting the special characters, like so:

sudo apt purge wine\*

or equivalently:

sudo apt purge 'wine*'

The reason that you might see it work in a different directory, is that when no files match the pattern, the glob is left as is, e.g. with the literal asterisk. So if you ran your command in a different directory it would probably work. But to be on the safe side it is always a good idea to quote/escape any special bash characters, if you want them passed on to the command you are running.

This behavior can be avoided by setting the nullglob bash option with the command

shopt -s nullglob

If this option is enabled, then any pattern that doesn't match files will be set to null instead of retaining its initial value, so it will be much easier to spot such bugs. It's really unfortunate that this option is not enabled by default, it would avoid countless erratic bugs that are only apparent if the right files exist in the current directory.