will usually find the correct package and version for your install setup and just install everything
sudo apt-get update
sudo apt-get install php-gd
sudo service apache2 restart
For 5.6 PHP
sudo apt-get install php5.6-gd
For 7.0 PHP
sudo apt-get install php7.0-gd
For 8.0 PHP
sudo apt-get install php8.0-gd