How to install PostGIS in Ubuntu

How to install PostGIS in Ubuntu

In this article, we will see How to install PostGIS in Ubuntu.

What is Postgis?

PostGIS is a spatial database extender for PostgreSQL object-relational database. It adds support for geographic objects allowing location queries to be run in SQL. postgis is just extension to existing database. That also we have to add as shown below.

Prerequisites to install postgis extension on Linux:

1. PostgreSQL must be installed.
2. Internet connection.
3. Sudo or root privileges.

Steps to install Postgis in Ubuntu

1. Install potgis extension on Ubuntu using apt-get.

sudo apt-get install postgis

Type Y and press enter.

How to install Postgis in Ubuntu

2. Connect to PostgreSQL server

sudo su - postgres

3. List all available databases.

\l select datname from pg_database;

4. Connect to specific database to which, we have to add extension.

\c r2schools

5. Lets verify postgis extension is already added or not.

SELECT e.extname AS "Name", e.extversion AS "Version", n.nspname AS "Schema", c.description AS "Description" FROM pg_catalog.pg_extension e LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass ORDER BY 1;

or

\dx

6. Run the following command to add postgis extension.

CREATE EXTENSION postgis;

7. Lets verify postgis extension is added or not.

SELECT e.extname AS "Name", e.extversion AS "Version", n.nspname AS "Schema", c.description AS "Description" FROM pg_catalog.pg_extension e LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace LEFT JOIN pg_catalog.pg_description c ON c.objoid = e.oid AND c.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass ORDER BY 1;

or

\dx

So, in this article, we have seen How to install PostGIS in Ubuntu.