'php8.0-dev package installs PHP 8.1 dependencies

When I try to install the php8.0-dev package (apt-get install php8.0-dev) http://ppa.launchpad.net/ondrej/php/ubuntu repository on Ubuntu 20.04, it installs some php8.1 dependencies. Any ideas how I can solve this? Thank you!

Here are the dependencies:

  groff-base intltool-debian libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libarchive-cpio-perl libarchive-zip-perl
  libcroco3 libdebhelper-perl libdpkg-perl libelf1 libfakeroot libfile-fcntllock-perl libfile-stripnondeterminism-perl libglib2.0-0
  libglib2.0-data liblocale-gettext-perl libmail-sendmail-perl libpcre2-16-0 libpcre2-32-0 libpcre2-dev libpcre2-posix2 libpipeline1
  libssl-dev libstdc++-9-dev libsub-override-perl libsys-hostname-long-perl libuchardet0 make man-db php-json php-pear php8.0-dev php8.1-cli
  php8.1-common php8.1-opcache php8.1-phpdbg php8.1-readline pkg-config pkg-php-tools po-debconf shared-mime-info shtool xdg-user-dirs```


Solution 1:[1]

sudo apt install... installs recommended packages by default. By passing the --no-install-recommends option, the user lets apt know not to consider recommended packages as a dependency to install, and to install only the minimal subset of required dependencies.

Open the terminal and type:

sudo apt install --no-install-recommends php8.0-dev

The above command will still install some of the packages in the list in your question anyway because they are required dependencies of php8.0-dev. The following packages are dependencies of php8.0-dev.

Package: php8.0-dev
Source: php8.0
Depends: autoconf (>= 2.63), automake (>= 1.11), libpcre2-dev (>= 10.30), libssl-dev, pkg-config, php8.0-cli (>= 8.0.14-1+ubuntu20.04.1+deb.sury.org+1), php8.0-common (= 8.0.14-1+ubuntu20.04.1+deb.sury.org+1), shtool, libtool (>= 2.4.6-0.1~)

These dependencies were copied from the Packages.gz archive at http://ppa.launchpad.net/ondrej/php/ubuntu/dists/focal/main/binary-amd64/ . The list of dependencies from the Packages.gz archive is shorter than the list of dependencies in your question because some of these dependencies have dependencies themselves which also must be installed in order to install php8.0-dev.

If you manage to successfully install php8.0-dev without recommended packages and change your mind and want to install the recommended packages anyway your original command would do it.

sudo apt install php8.0-dev

According to the results of rmadison php8.0-dev php8.0-dev is in the default repositories of Ubuntu 21.10, so maybe its .deb file could be installed in Ubuntu 20.04. I downloaded the .deb file and simulated installing it in Ubuntu 20.04, but I couldn't install it. That's one of the reasons why there is a PHP PPA, but if I were you I'd consider upgrading to the latest version of Ubuntu anyway.

If all these apt-based solutions aren't suitable you'll have to build php8.0-dev and possibly some of its dependencies from source.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1