Install Wine and keep PHP PPA🔗

Have you been hunting for hours if not days to find a way to install wine form WineHQ and just cannot install it?

You might also have Ondřej's PPA installed.

When you try to install it, you will most likely get this error:

The following packages have unmet dependencies:
 libgphoto2-6:i386 : Depends: libgd3:i386 (>= 2.1.0~alpha~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Most say you just need to remove Ondřej's PPA and downgrade packages to the ones available on Ubuntu or Debian (or whatever you are using).

In my case, as a software developer who uses PHP among other languages, this was not an acceptable solution.

What you can do is simply downgrade 1 or 2 packages, and wine will install just fine with the WineHQ repository.

This post assumes you have been following the install instructions here: https://gitlab.winehq.org/wine/wine/-/wikis/Debian-Ubuntu

If you have purged everything Wine so far, simply run the steps up (not including) to "Install Wine", and then follow the below steps.

Run the following command to find the version of libgd3 to install:

apt-cache madison libgd3

You'll get an output that looks like this:

    libgd3 | 2.3.3-12+ubuntu22.04.1+deb.sury.org+1 | https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy/main amd64 Packages
    libgd3 | 2.3.0-2ubuntu2 | http://apt.pop-os.org/ubuntu jammy/main amd64 Packages
    libgd2 | 2.3.0-2ubuntu2 | http://apt.pop-os.org/ubuntu jammy/main Sources

Look at the second line, and install that version; to do that, you simply type the package name, equal sign, followed by the version string. In my case, that looks like this:

apt install libgd3=2.3.0-2ubuntu2

You will also need to install the 32bit version:

apt install libgd3:i386=2.3.0-2ubuntu2

Then you need to hold the packages, so they won't be upgraded, because Ondřej's PPA will upgrade the packages otherwise:

apt-mark hold libgd3 libgd3:i386

Now you can install Wine as usual (below is STABLE, look at WineHQ wiki for other versions.):

apt install wine-stable winehq-stable

And you're done!