Home  »  ArticlesGuidesHow ToTechnologyTools   »   How to Install the Latest PostGIS on Ubuntu 22.04

How to Install the Latest PostGIS on Ubuntu 22.04

PostGIS is a powerful open-source spatial database extension for PostgreSQL that allows you to store, query, and manipulate geographic and geometric data. If you’re using Ubuntu 22.04 and need to set up the latest version of PostGIS for your spatial data needs, you’re in the right place. In this guide, we’ll walk you through the step-by-step process to install the latest PostGIS on your Ubuntu 22.04 system.


Before you start the installation process, make sure you have the following prerequisites in place:

  1. Ubuntu 22.04 LTS installed on your system.
  2. PostgreSQL installed and configured on your system
  3. Administrative (sudo) privileges.

Step 1: Update Your System

It’s always a good practice to ensure your system is up to date before installing any new software. Open a terminal and run the following commands:

$ sudo apt update
$ sudo apt upgrade

This will update the package lists and upgrade any existing packages to their latest versions.

Step 2: Install PostgreSQL

PostGIS is an extension for PostgreSQL, so you’ll need to have PostgreSQL installed. If it’s not already on your system, you can install it with the following command:

$ sudo apt install postgresql postgresql-contrib

Step 3: Install PostGIS

Now that PostgreSQL is installed, you can proceed to install PostGIS. Ubuntu 22.04’s default repositories may not always have the latest version of PostGIS, but you can use the PostgreSQL apt repository to get the most recent version. Here’s how:

3.1: Add the PostgreSQL Repository

$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

3.2: Import the Repository Signing Key

$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

3.3: Install PostGIS

Now, update the package list again and install PostGIS:

$ sudo apt update
$ sudo apt install postgis postgresql-<version>-postgis-<version>

Replace <version> with the specific PostgreSQL and PostGIS versions you want to install. For example, for PostgreSQL 14 and PostGIS 3, use:

$ sudo apt install postgis postgresql-14-postgis-3

Step 4: Create a PostGIS-enabled Database

Once PostGIS is installed, you can create a new PostgreSQL database and enable PostGIS in it. Replace <your_database> with your desired database name:

$ sudo -u postgres createdb <your_database>
$ sudo -u postgres psql -d <your_database> -c "CREATE EXTENSION postgis;"

Step 5: Verify the Installation

To ensure that PostGIS is installed correctly and functioning, you can connect to your PostGIS-enabled database and run a simple query:

$ sudo -u postgres psql -d <your_database>

Inside the PostgreSQL prompt, run the following query:

SELECT postgis_version();

This query should return the version of PostGIS you installed, confirming that the installation was successful.


You’ve now successfully installed the latest version of PostGIS on your Ubuntu 22.04 system. You can use this powerful spatial extension to work with geographic and geometric data in your PostgreSQL databases. If you encounter any issues or need further assistance, consult the PostGIS documentation or seek help from the PostGIS community to make the most of this valuable tool for spatial data management.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Articles, Guides, How To, Technology, Tools