In this tutorial, I will guide you on how to install PostGIS on Ubuntu 20.04. In the previous article, I have shown how to install PostGIS on Ubuntu 18.04. I want to update the article with the new version of Ubuntu. When this article is being written, the new PostgreSQL Server version 12 is available in the Ubuntu repository. So, we are going to use that version here.
PostGIS is a spatial database that can be used to store the GIS dataset inside PostgreSQL Server. PostGIS works very well on QGIS and some other GIS software such as MapInfo and ArcGIS. So in this article, I also include some short videos showing the command lines in progress. I hope this will help you who just started to use Ubuntu or PostgreSQL.
Steps to Install PostGIS on Ubuntu 20.04
Step 1. Install PostgreSQL Server
Open Ubuntu Terminal and then update your system
sudo apt update && sudo apt upgrade
Next, install PostgreSQL Server
sudo apt install postgresql
After install, execute this command to start PostgreSQL service
pg_ctlcluster 12 main start
And then check the PostgreSQL server status
sudo systemctl status postgresql
Step 2. Install PostGIS
Now we are going to install PostGIS on Ubuntu 20.04. Use this command to install it.
sudo apt install postgis
Watch the entire installation process below.
At this step, we have successfully installed PostGIS extension on the PostgreSQL server. Now, we need to create a new database and then enable the PostGIS extension on that database. If you have the database already, we can also enable the PostGIS on the existing database.
Create a new database
To create a new PostgreSQL database from the command line, we need to connect/login to the PostgreSQL server as postgres user first.
sudo -i -u postgres
Now we are in the postgres user. Execute this command to create a new database called “gis_database”.
Watch the entire new database creation process below.
Enable PostGIS extension on the database
Now we have a new database and let’s enable the postgis extension on this new database.
Step 3. Enable Remote Access
By default, we can only access the PostgreSQL database from localhost. We need to enable remote access to the server so the network users can access the PostgreSQL server from the network. We need to modify two things.
Edit the pg_hba.conf
In my case, the file pg_hba.conf is located under /etc/postgresql/12/main. We can edit using nano or any text editor you prefer.
sudo nano /etc/postgresql/12/main/pg_hba.conf
Add the following line to the end of the file
host all all 0.0.0.0/0 md5
Next, we need to edit the file postgresql.conf. It’s in the same folder as pg_hba.conf.
sudo nano /etc/postgresql/12/main/postgresql.conf
Find the line that says
#listen_addresses = 'localhost'
Change it to
listen_addresses = '*'
Thank you. I hope you enjoy it and see you next time. For more information, please visit the official website of PostgreSQL below.
YoannNovember 25, 2020
Excellent and clear article, thanks a lot!
A little typo in Step 2 though, you wrote:
“sudo apt install postgi”
where it should be:
“sudo apt install postgis”
How to Install PostGIS on Ubuntu 22.04 - GIS TutorialMay 19, 2022
[…] Ubuntu 22.04. Ubuntu 22.04 is the latest LTS version of Ubuntu. I have written a similar article to install and configure PostGIS on Ubuntu 20.04. You can check that post if you want. Basically, it is a pretty identical step but for the sake of […]