Install php8.1-gd on Debian System

If you are facing any issues with installing php-gd library on your system then you are at the right place to find the solution. Just follow me for the steps to install gd library. It is not as easy as installing other extensions of php because it depends on some other system softwares/libraries. Today we will install all those dependencies and php-gd.

The php-gd package isn't available in Debian repositories (yet). But that doesn't matter, of course you can install it anyway. There's a great website named DEB.SURY.ORG that packages different software into Debian and Ubuntu (especially PHP packages).

First, download the key to the package source:

sudo curl -s https://packages.sury.org/php/apt.gpg | sudo apt-key add -

Then create a .list file in /etc/apt/sources.list.d/:

echo "deb https://packages.sury.org/php/ buster main" | sudo tee /etc/apt/sources.list.d/php.list

Then update and upgrade your distro:

sudo apt update -y && sudo apt dist-upgrade -y

Now you should be able to install the php8.1-gd package by running. Maybe you can replace the php version with your installation eg. php7.3-gd:

sudo apt install php8.1-gd

You are almost done but maybe you can face some errors like :

The following packages have unmet dependencies:
 libgd3 : Depends: libwebp6 (>= 0.5.1) but it is not installable
E: Unable to correct problems, you have held broken packages.

In this case you will need to install few more dependencies:

sudo apt-get -y install apt-transport-https lsb-release ca-certificates
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt-get update
sudo apt-get install php8.1-gd

Congratulations! you have gd library installed. If you have any further questions please do leave comments.
Thanks!