sudo apt-get update
sudo apt install -y software-properties-common ca-certificates lsb-release apt-transport-https
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt install -y php7.4 php7.4-common php7.4-mysql php7.4-xml php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip
php -v
php -m
You can use the update-alternatives
command to set the default PHP version.
Read more details about switching PHP version for CLI and Apache
sudo update-alternatives --config php
sudo apt remove php7.4
Also, uninstall all the modules for that version with the following command:
sudo apt remove php7.4-*