This is more difficult than expected when going against the grain of the latest releases, which is possible using the http://apt.postgresql.org/pub/repos/apt
.
For example, when using postgresql-11 installations, simply adding postgis attempts to also add postgresql-12 !
$ dpkg -l | grep postg
ii pgdg-keyring 2018.2 all keyring for apt.postgresql.org
ii postgis-doc 2.4.3+dfsg-4 all Geographic objects support for PostgreSQL -- documentation
ii postgresql-11 11.7-2.pgdg18.04+1 amd64 object-relational SQL database, version 11 server
ii postgresql-11-pgrouting 3.0.0~rc1-1.pgdg18.04+1 amd64 Routing functionality support for PostgreSQL/PostGIS
ii postgresql-11-pgrouting-scripts 3.0.0~rc1-1.pgdg18.04+1 all Routing functionality support for PostgreSQL/PostGIS - SQL scripts
ii postgresql-11-postgis-2.5 2.5.4+dfsg-1.pgdg18.04+1 amd64 Geographic objects support for PostgreSQL 11
ii postgresql-11-postgis-2.5-scripts 2.5.4+dfsg-1.pgdg18.04+1 all Geographic objects support for PostgreSQL 11 -- SQL scripts
ii postgresql-client-11 11.7-2.pgdg18.04+1 amd64 front-end programs for PostgreSQL 11
ii postgresql-client-common 213.pgdg18.04+1 all manager for multiple PostgreSQL client versions
ii postgresql-common 213.pgdg18.04+1 all PostgreSQL database-cluster manager
ii postgresql-plpython-11 11.7-2.pgdg18.04+1 amd64 PL/Python procedural language for PostgreSQL 11
ii postgresql-plpython3-11 11.7-2.pgdg18.04+1 amd64 PL/Python 3 procedural language for PostgreSQL 11
ii postgresql-server-dev-11 11.7-2.pgdg18.04+1 amd64 development files for PostgreSQL 11 server-side programming
$ sudo apt-get install postgis
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
postgresql-12 postgresql-12-postgis-3 postgresql-12-postgis-3-scripts postgresql-client-12
Suggested packages:
postgis-gui postgresql-doc-12
The following NEW packages will be installed:
postgis postgresql-12 postgresql-12-postgis-3 postgresql-12-postgis-3-scripts postgresql-client-12
0 upgraded, 5 newly installed, 0 to remove and 21 not upgraded.
Need to get 336 kB/20.6 MB of archives.
After this operation, 90.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] n
Abort.
There is no option for a postgis-11 set of utils. If everything else is on the latest versions, it just-works.
Trying to install only the postgis package sorta works, but it installs a 3.x version rather than a matching 2.x version, e.g.
$ sudo apt-get install --no-install-recommends postgis
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
postgis-gui
Recommended packages:
postgresql-12-postgis-3
The following NEW packages will be installed:
postgis
0 upgraded, 1 newly installed, 0 to remove and 23 not upgraded.
Need to get 336 kB of archives.
After this operation, 1,621 kB of additional disk space will be used.
Get:1 http://apt.postgresql.org/pub/repos/apt bionic-pgdg/main amd64 postgis amd64 3.0.1+dfsg-2.pgdg18.04+1 [336 kB]
Fetched 336 kB in 2s (215 kB/s)
Selecting previously unselected package postgis.
(Reading database ... 374551 files and directories currently installed.)
Preparing to unpack .../postgis_3.0.1+dfsg-2.pgdg18.04+1_amd64.deb ...
Unpacking postgis (3.0.1+dfsg-2.pgdg18.04+1) ...
Setting up postgis (3.0.1+dfsg-2.pgdg18.04+1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...