I wrote many tutorials about PostGIS installation on different systems here in this blog. And today, we will learn how to install PostGIS on Ubuntu 22.10. I know that Ubuntu 22.10 is a regular release, not LTS. But, still, it is a great operating system that I won’t miss. PostGIS is a great extension for the PostgreSQL database. We can store spatial data in the database and use it with most GIS software such as QGIS and ArcGIS Pro.
In this example, I am using Ubuntu 22.10 Server edition installed on Proxmox hosts. Proxmox is a great way to build your own home labs. Find out more about Proxmox and try it yourself.
Steps to Install PostGIS on Ubuntu 22.10
In order to install PostGIS on Ubuntu 22.10, we will do the following:
- Update Ubuntu
- Install PostgreSQL Server
- Create a new database and user
- Install PostGIS extension
- Test PostGIS connection
Step 1. Update Ubuntu
It is good to always have our system up to date with any security updates. So, let’s do it before we do anything else. Open the Terminal or connect to the Ubuntu 22.10 server via SSH. And the use this command to update Ubuntu.
sudo apt update && sudo apt upgrade
Step 2. Install PostgreSQL Server
PostGIS is a PostgreSQL Server extension. So, we need to install PostgreSQL first before we can install PostGIS. In Ubuntu, use this command to install PostgreSQL Server.
sudo apt install postgresql postgresql-contrib
dhani@ubuntuserver-2210:~$ sudo apt install postgresql postgresql-contrib Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5 libsensors-config libsensors5 libtypes-serialiser-perl postgresql-14 postgresql-client-14 postgresql-client-common postgresql-common ssl-cert sysstat Suggested packages: lm-sensors postgresql-doc postgresql-doc-14 isag The following NEW packages will be installed: libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5 libsensors-config libsensors5 libtypes-serialiser-perl postgresql postgresql-14 postgresql-client-14 postgresql-client-common postgresql-common postgresql-contrib ssl-cert sysstat 0 upgraded, 16 newly installed, 0 to remove and 0 not upgraded. Need to get 42.1 MB of archives. After this operation, 162 MB of additional disk space will be used. Do you want to continue? [Y/n]
Now let’s start the service
sudo service postgresql start sudo service postgresql status
dhani@ubuntuserver-2210:~$ sudo service postgresql status ● postgresql.service - PostgreSQL RDBMS Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; preset: enabled) Active: active (exited) since Mon 2022-12-19 03:52:20 UTC; 3h 48min ago Process: 3222 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 3222 (code=exited, status=0/SUCCESS) CPU: 1ms Dec 19 03:52:20 ubuntuserver-2210 systemd: Starting PostgreSQL RDBMS... Dec 19 03:52:20 ubuntuserver-2210 systemd: Finished PostgreSQL RDBMS.
At this point, we have successfully installed PostgreSQL Server on Ubuntu 22.10.
Step 3. Create a new database and new role
Now we need to create a new role and database. You can see how to create a new role and database below.
In the example above, I created a new role called vtech and a new database called gis_database. By default, vtech user does not have password and it does not have access to the gis_database yet. Next, we will give permission to this user so it can access the new database.
Step 4. Install and Configure PostGIS
We have completed installing the PostgreSQL database and now we need to install PostGIS package in Ubuntu 22.10. Use this command to install the latest version of postgis in Ubuntu.
sudo apt install postgis
PostGIS extension has to be enabled on each database. It is not enabled by default, so let’s enable the postgis extension on our database.
dhani@ubuntuserver-2210:~$ sudo -i -u postgres postgres@ubuntuserver-2210:~$ psql -d gis_database gis_database=# CREATE EXTENSION postgis;
At this point, we have enabled the PostGIS extension on our new database.
Step 5. Enable Remote Access
At the moment, we have successfully installed the PostgreSQL database server as well as the PostGIS extension. But, our server is only accessible from the local host. Now we are going to make the server accessible from the network.
We need to edit pg_hba.conf file. Use your favorite text editor, for example, nano.
sudo nano /etc/postgresql/14/main/pg_hba.conf
At the end of the file, add the following line
host all all 192.168.100.0/24 trust
Don’t forget to change 192.168.100.0 with your own IP address. Or, you can also use 0.0.0.0 to allow all the IP addresses.
Allow TCP/IP Socket
Finally, we also need to edit the postgresql.conf.
sudo nano /etc/postgresql/14/main/postgresql.conf
And then find the following line:
#listen_addresses = 'localhost'
Change it to
listen_addresses = '*'
Close and save the file. Restart PostgreSQL Service
sudo service postgresql restart
Step 5. Test PostGIS Connection
Now we can start testing the connection to the PostGIS server. I am going to use QGIS.