Here’s the easiest way to get a very up-to-date installation of PostGIS up and running quickly. First up, set up the Postgres 9.5 repository straight from Postgres:
sudo rpm -ivh https://download.postgresql.org/pub/repos/yum/9.5/fedora/fedora-24-x86_64/pgdg-fedora95-9.5-3.noarch.rpm
Next up, install Postgres:
sudo dnf install postgresql95 postgresql95-server postgresql95-libs postgresql95-contrib postgresql95-devel
The -devel package is optional, but I will be building Ruby’s PG gem later so it needs to be there for me. If you have no such plans feel free to skip it. If you want a GUI to help manage the database add the ‘pgadmin3’ package to the list. Now it is time to initialize the database. Do so with:
sudo /usr/pgsql-9.5/bin/postgresql95-setup initdb
That will take a minute to run as it sets up the initial database. Once the database is initialized start Postgres with systemd by running:
sudo systemctl start postgresql-9.5
If you want Postgres to start at boot run the same command but change ‘start’ to ‘enable’ before you reboot or shutdown. Next up is a little housekeeping. Set a password for the Postgres account. I like to do this in the database itself rather than on the Postgres user account. To do so run:
sudo -i postgres psql postgres
This starts a psql session as the Postgres user then in psql allowing you to set the password with:
Next up since this is just a development box I’ll change Postgres’ login method from Ident to MD5.
sudo gvim /var/lib/pgsql/9.5/data/pg_hba.conf
Change all ‘peer’ and ‘ident’ to ‘md5’. If this is a production server you’ll want a more secure and robust login method. However, if you don’t want bother with passwords at all instead of ‘md5’ replace them ‘trust’. Next up is installing PostGIS. It and nearly all its dependencies are nicely packaged in the Postgres repository making it easy to keep the two in sync. Install PostGIS with:
dnf install postgis2_95 postgis2_95-client
As a test you can create a database called ‘test’ and enable PostGIS with:
sudo -u postgres createdb test
psql -d test -U postgres -W -c "CREATE SCHEMA postgis; CREATE EXTENSION postgis WITH SCHEMA postgis; ALTER DATABASE test SET search_path TO public, postgis;"
psql -d test -U postgres -W -c "SELECT postgis_full_version();"
If the last command returns information about the version of PostGIS installed you’re good to go. Have fun!