Multiple versions of PostGIS and PgRouting on CentOS 7
It won't work to install several versions of PostGIS in the same PostgreSQL software directory, since the resulting shared objects will have the same name. Using a different --prefix is not enough, since most of PostGIS is not installed there, but in the PostgreSQL software directory.

So you should make a copy of your PostgreSQL software directory and install the different PostGIS versions in different directories.

If you really need different versions of Proj, GDAL etc. (why?), things become difficult, and you'd have to use a different LD_LIBRARY_PATH for each instance.

But perhaps it is much simpler, since the recent versions of PostGIS are binary compatible and come with installation scripts for several versions.

So maybe you can do with just installing the most recent PostGIS version and using different versions in different databases:

CREATE EXTENSION postgis VERSION 2.4.0;