@aimme's answer should be accepted!
I would extend his answer with @david-baucum's comment because his explanation is clear!
I would also extend his answer that you can run multiple PHP versions at the same time using ppa:ondrej/php
.
Then you don't need to change the PHP version simple call the composer like this:
/usr/bin/php7.2 /usr/local/bin/composer install