Install PostGIS on Ubuntu


I have tried this method successfully with Ubuntu 16/18/20, which is great because probably it will still work for a while. Also it is pretty straightforward 🙂

1 – Install PostGIS

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install postgis

Actually you are already done. The rest of this blog post is interesting if you want to go ahead and create your first PostGIS database and user.

Optional – Create your first PostGIS database and user

# Let's connect as user postgres
sudo -i -u postgres
# Next let's launch a postgres command-line session

Your prompt should look similar to mine

Now inside this prompt we will work

postgres=# create database myDatabase;
postgres=# create user myUser with password 'myPassword';
postgres=# grant all privileges on database myDatabase to myUser;
postgres=# \c myDatabase;
postgres=# CREATE EXTENSION postgis;
postgres=# SELECT PostGIS_version();
postgres=# \q


That’s it. If you want to connect to your new database with your new user just do

>>> PGPASSWORD="myPassword" psql -h localhost -U myUser -d myDatabase