If you are starting with databases and want to work with spatial data, PostgreSQL combined with PostGIS is a powerful solution. PostgreSQL is a robust, open-source relational database system known for its flexibility, reliability, and advanced features. Adding PostGIS to PostgreSQL allows you to manage geographic and location-based data effectively, which is essential for GIS applications, mapping, and spatial analysis. In this beginner-friendly tutorial, we’ll walk you through the process to install PostgreSQL on Ubuntu 24.04 and enable the PostGIS extension.

Step 1: Update Your System

Before installing any software, it’s always a good practice to update your system. Open your terminal and run:

sudo apt update

sudo apt upgrade -y

 

Updating ensures you have the latest security patches and software versions, providing a stable environment for PostgreSQL installation.

Step 2: Install PostgreSQL

Ubuntu 24.04 comes with PostgreSQL in its default repositories. To install it, use the following command:

sudo apt install postgresql postgresql-contrib -y

 

The postgresql-contrib package contains additional useful tools and extensions that enhance PostgreSQL’s functionality. After installation, PostgreSQL will start automatically. You can check the status with:

sudo systemctl status postgresql

 

You should see that the service is active and running, which means PostgreSQL is ready to use.

Step 3: Access the PostgreSQL User Account

PostgreSQL uses a default system user called postgres. Switch to this user to manage your databases:

sudo -i -u postgres

 

Once switched, you can access the PostgreSQL command-line interface with:

psql

 

Exit the interface anytime by typing \q.

Step 4: Create Your Database

Before enabling PostGIS, create a new database to store your spatial data. For example, create a database named gisdb with:

createdb gisdb

 

This database will host your PostGIS-enabled tables and spatial features.

Step 5: Install the PostGIS Extension

Now let’s cover the main topic: how to install PostGIS extension in PostgreSQL. PostGIS adds spatial capabilities to PostgreSQL, allowing you to store and query geographic objects like points, lines, and polygons. Install PostGIS with:

sudo apt install postgis postgresql-*-postgis-3 -y

 

After installation, connect to your database and enable the extension:

psql -d gisdb

CREATE EXTENSION postgis;

\q

 

This command activates PostGIS, making spatial functions available for your database operations.

For more detailed instructions, visit the official guide on Vultr’s website. The resource provides step-by-step explanations, troubleshooting tips, and additional configurations to ensure PostGIS runs smoothly on your system.

Step 6: Verify PostGIS Installation

To ensure PostGIS is installed correctly, connect to your database and run:

SELECT PostGIS_Version();

 

You should see the version number of PostGIS installed, confirming that the extension is active and ready for spatial queries.

Conclusion

Installing PostgreSQL on Ubuntu 24.04 and enabling the PostGIS extension opens up a wide range of possibilities for managing spatial data. From geographic mapping to advanced spatial analysis, PostgreSQL with PostGIS is a reliable solution for developers, GIS professionals, and hobbyists alike. By following this beginner-friendly tutorial, you can quickly set up a PostgreSQL database with full spatial capabilities.

For a complete, step-by-step guide with official commands and troubleshooting advice, visit Vultr’s guide on installing the PostGIS extension in PostgreSQL. This ensures a smooth installation and helps you get started with spatial data management efficiently.