0

How To Install PostGIS on Ubuntu 20.04/18.04 | Debian 10

 2 years ago
source link: https://computingforgeeks.com/how-to-install-postgis-on-ubuntu-debian/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How To Install PostGIS on Ubuntu 20.04/18.04
Search

Today’s guide will cover how to install PostGIS on Ubuntu 20.04/18.04 | Debian 10 Linux. PostGIS is an open source PostgreSQL database extension for creating Geographic objects on the PostgreSQL object relational database. The features of PostGIS are derived from Open Geospatial Consortium SQL specifications.

postgis debian ubuntu

PostGIS can be installed on Ubuntu, Debian, SUSE Linux, Red Hat based Linux systems such as CentOS, Scientific Linux, Windows and macOS. The PostgreSQL build team has packages for Debian and Ubuntu for several versions of PostgreSQL. We’ll add the PostGIS APT repository for PostgreSQL and install PostGIS on Ubuntu 20.04/18.04 / Debian 10 from it.

Let’s now kickstart the installation of PostGIS on Ubuntu 20.04/18.04 / Debian 10 Linux system.

Step 1: Update system

You can do APT package list update and system upgrade before you get started.

sudo apt update
sudo apt -y upgrade

A reboot is necessary after an upgrade.

sudo reboot

Step 2: Add PostgreSQL repository

Before you start the installation of PostGIS on Ubuntu 20.04/18.04 / Debian 10 Linux, you’ve to add PostgreSQL APT repository to your system where binary packages will be downloaded and installed.

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

After importing GPG key, add PostgreSQL APT repository.

echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee  /etc/apt/sources.list.d/pgdg.list

Step 3: Install PostgreSQL Database Server

PostgreSQL is required to be installed before installation of PostGIS on Debian / Ubuntu. Use our previous guides for this installation.

PostgreSQL 11:

Install PostgreSQL 11 on Ubuntu

Install PostgreSQL 11 on Debian 10

PostgreSQL 12:

Install PostgreSQL 12 on Ubuntu

Install PostgreSQL 12 on Debian 10

For different version of PostgreSQL, replace version number with your desired installation version.

Step 4: Install PostGIS on Ubuntu 20.04/18.04 / Debian 10

After the installation of PostgreSQL, proceed to install PostGIS on Ubuntu 20.04/18.04 / Debian 10 Linux distribution.

With PostgreSQL 12:

sudo apt install postgis postgresql-12-postgis-3

The next is for PostgreSQL 11. Replace 11 with your PostgreSQL version.

sudo apt update
sudo apt install postgis postgresql-11-postgis-3

Step 5: Enable PostGIS on Debian 10 / Ubuntu 20.04/18.04

You need to activate PostGIS features on a database before you can store spacial data. The example below will show you how to create a database and activate the Spacial features.

1.Switch to postgres user.

sudo -i -u postgres

2.Create test user/database.

-bash-4.2$ createuser postgis_test
-bash-4.2$ createdb postgis_db -O postgis_test

3.Connect to the test database:

-bash-4.2$ psql -d postgis_db
psql (11.5 (Debian 11.5-3.pgdg100+1))
Type "help" for help.

4.Enable the PostGIS extension on the database:

postgis_db=# CREATE EXTENSION postgis;
CREATE EXTENSION

5. Verify PostGIS is working

postgis_db=# SELECT PostGIS_version();
            postgis_version            
---------------------------------------
 2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
(1 row)

For more PostGIS mastery, visit the PostGIS Documentation website.

Similar guides:

Install PostGIS on CentOS 7

How To Install pgAdmin 4 on Ubuntu

How to Install pgAdmin 4 on Debian

How to Install pgAdmin 4 on CentOS 7 & Fedora

How to Install pgAdmin4 on FreeBSD 12


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK