How to choose default version of CLI PHP on Ubuntu?

php cli configuration pecl

Having several PHP versions on development machine is really desired. However when new version pops in, not everything might work. To bring back your favorite version as default, Ubuntu has a built-in facility for it. 

Just run command and choose specific version:

sudo update-alternatives --config php

This can also update many different things

For instance when building PHP modules from source phpize command and php-config can be selected too:

sudo update-alternatives --config phpize
sudo update-alternatives --config php-config 

Installing PECL extension for many PHP versions

Even if you select desired php, phpize and php-config version, the pecl command will notify you that extension is already installed, if it was installed for any PHP version. To install extension for specific PHP, first choose right version with commands above, then install with -f flag:

sudo pecl install -f <extension-name>

Choosing other alternatives

Run this command to choose all manual alternatives:

sudo update-alternatives --all --skip-auto