PostGIS is an open-source extension for PostgreSQL that adds support for geographic objects, enabling spatial queries and GIS functionality. Installing PostGIS on Ubuntu 24.10 is straightforward, and this guide will walk you through the process step by step. I use the Ubuntu 24.10 Server edition, which is installed on my Proxmox VE host.
If you are planning to use the RDBMS to store your spatial data, PostGIS could be a good solution. It is powerful, supports many GIS software, and is free.
Prerequisites
Before you begin, there are a couple of things that we need:
- You have a machine running Ubuntu 24.10.
- You have administrative privileges or root access.
- PostgreSQL is installed on your system.
Steps to Install PostGIS in Ubuntu 24.10
Step 1: Update Your System
First, update the system package index and upgrade installed packages to their latest versions:
sudo apt update
sudo apt upgrade -y
Step 2: Install PostgreSQL (if not already installed)
If PostgreSQL is not already installed, you can install it using the following command:
sudo apt install -y postgresql postgresql-contrib
After installation, start the PostgreSQL service and enable it to start on boot:
sudo systemctl start postgresql
sudo systemctl enable postgresql
Now, check the service status, make sure it is up and running
sudo systemctl status postgresql
Step 3. Install Postgis
Now let’s install the Postgis extension. Simply use this single command to install the Postgis package in Ubuntu 24.10.
sudo apt install postgis
Step 4. Enable Postgis in a Database
Postgis has to be enabled in every database that we want. It’s not enabled by default on all the databases. So, we need to do it manually. We don’t have the database yet. Now let’s create a new database and create postgis extension in the new database.
Switch to postgres user
sudo -i -u postgres
Now access the PostgreSQL shell
psql
Create a new database
CREATE DATABASE gis;
Connect to the newly created database
\c gis
Create postgis extension
CREATE EXTENSION postgis;
CREATE EXTENSION postgis_topology;
Verify the installation
SELECT PostGIS_Full_Version();
It should show something like this:
postgis_full_version
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POSTGIS="3.4.2 c19ce56" [EXTENSION] PGSQL="160" GEOS="3.12.2-CAPI-1.18.2" PROJ="9.4.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org USER_WRITABLE_DIRECTORY=/tmp/proj DATABASE_PATH=/usr/share/proj/proj.db" LIBXML="2.12.7" LIBJSON="0.17" LIBPROTOBUF="1.4.1" WAGYU="0.5.0 (Internal)" TOPOLOGY
(1 row)
Exit the PostgreSQL Shell
\q
We have successfully created a new database (gis) and enabled postgis extension to the database.
Step 5. Add a New User and Grant Permission
To allow a specific user to access your database, follow these steps:
Create a new PostgreSQL user:
sudo -i -u postgres
psql
Now create a new user
CREATE USER dhani WITH PASSWORD 'Test.12345';
Grant the database to the new user
GRANT ALL PRIVILEGES ON DATABASE gis TO dhani;
Now the new user has the access to the new database (gis).
Step 6. Configure PostgreSQL for Remote Access
By default, PostgreSQL is only accessible to localhost. You won’t be able to connect to it from the network. If you need this enabled, we need to follow the following steps:
Edit the PostgreSQL Configuration file
sudo nano /etc/postgresql/16/main/postgresql.conf
Locate this line in the configuration file:
listen_addresses = 'localhost'
Please change it to
listen_addresses = '*'
Close and save nano file editor using CTRL + X.
Edit pg_hba.conf
Add this line to the pg_hba.conf file
host all all 0.0.0.0/0 md5
Close and finally let’s restart PostgreSQL service
sudo systemctl restart postgresql
Conclusion
You’ve successfully installed and configured PostGIS on Ubuntu 24.10! With PostGIS, you can now perform advanced spatial queries and analysis directly within your PostgreSQL databases. If you encounter any issues, consult the PostGIS documentation for additional support.