Install PostreSQL 14 and PostGIS 3 on Ubuntu 22.04 LTS

I always get frustrated when I update my version of Ubuntu to the next LTS and want to do some development work with the latest stable releases of PostgreSQL and PostGIS. 

I usually trawl a few web sites to find out what has changed but each time there are slightly different ways of doing the upgrade depending on where you land and who it is doing it. (hopefully) help other people out wasting half a day or so here is my solution. 

Hope this works for you too...

To completely remove all previous installed versions of Postgresql/PostGIS libraries and docs if there is a previous version:- 

:$ sudo apt --purge remove postgresql postgresql-* 
:$ sudo apt autoremove 

Remove old folders:- 

:$ sudo rm -rf /var/lib/postgresql/ 
:$ sudo rm -rf /var/log/postgresql/ 
:$ sudo rm -rf /etc/postgresql/ 

 Remove the old 'postgres' user:-

:$ sudo deluser postgres 

 Restart System:- 

:$ sudo shutdown -r now


Update System after restart:- 

:$ sudo apt update && sudo apt upgrade 

Install Postgresql-14-postgis-3:- 

:$ sudo apt -y install gnupg2 
:$ wget --quiet -O - | sudo apt-key add - 
:$ echo "deb `lsb_release -cs`-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list 
:$ sudo apt update 
:$ sudo apt install postgis postgresql-14-postgis-3 
:$ sudo -i -u postgres 
:$ createuser postgis_test 
:$ createdb postgis_db -O postgis_test 
:$ psql -d postgis_db 
:$ sudo -u postgis_test psql postgis_db 
:$ postgis_db=# CREATE EXTENSION postgis; 
:$ postgis_db=# SELECT PostGIS_version(); 

Connect to the test database:- 

:$ sudo -i -u postgres 
:$ postgres@myuser:$ psql -d postgis_db 
:$ postgis_db=# 

To exit back to your prompt:-

:$ \q 
:$ exit 

Connect to postgis_db (without a password) or to set/reset a password:- 

 :$ sudo -u postgres psql postgis_db 
 :$ postgis_db=# ALTER USER postgis_test WITH PASSWORD 'geometry'; 
 :$ postgis_db=# \q 

 In QGIS make a new 'PostGIS' connection:-

username: postgis_test
database: postgis_db
host i.p. (local)
password: geometry


Popular posts from this blog

Qgis-server...Installing the QGIS Lizmap Plugin & Lizmap Web Client

Install QGIS 3.22 LTS with QGIS-SERVER-3.22 and Apache2 on Ubuntu 22.04 LTS