Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lpf23/6ae3411682e59f33cbe37a467a6fb8a5 to your computer and use it in GitHub Desktop.
Save lpf23/6ae3411682e59f33cbe37a467a6fb8a5 to your computer and use it in GitHub Desktop.
PostgreSQL 12 with PostGIS 3.1.5 Installation on AmazonLinux2
##### Steps to Install PostgresSQL 12 with PostGIS 3.1.5 on AmazonLinux2 #####
# Install packages #
####################
$> sudo amazon-linux-extras install -y postgresql12 vim epel
$> sudo yum-config-manager --enable epel -y
$> sudo yum update -y
$> sudo yum install -y make automake gcc gcc-c++ libcurl-devel proj-devel pcre-devel autoconf automake libxml2-devel git cmake libtool libtiff-devel
$> sudo yum install -y postgresql-server postgresql-devel postgresql-server-devel postgresql-contrib
# Enable and Initialize PostgreSQL #
####################################
$> sudo systemctl enable postgresql
$> sudo su - postgres
$> postgresql-setup --initdb --unit postgresql
# Start PostgreSQL #
####################
$> sudo systemctl start postgresql
# Install sqlite3 #
###################
$> mkdir ~/postgis && cd ~/postgis
$> curl https://www.sqlite.org/2020/sqlite-autoconf-3320300.tar.gz | tar xzf -
$> cd sqlite-autoconf-3320300
$> ./configure --prefix=/usr/local && make && sudo make install
$> export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# Install GEOS 3.9.2 #
######################
$> cd ~/postgis
$> curl https://download.osgeo.org/geos/geos-3.9.2.tar.bz2 | tar xjvf -
$> cd geos-3.9.2
$> ./configure --prefix=/usr/local && make && sudo make install
# Install TIFF 4.3.0 #
######################
$> cd ~/postgis
$> curl -O https://download.osgeo.org/libtiff/tiff-4.3.0.zip
$> unzip tiff-4.3.0.zip
$> cd tiff-4.3.0/
$> ./configure --prefix=/user/local && make && sudo make install
# Install PROJ 7.2.1 #
######################
$> cd ~/postgis
$> curl https://download.osgeo.org/proj/proj-7.2.1.tar.gz | tar xzf -
$> cd proj-7.2.1
$> ./configure --prefix=/usr/local && make && sudo make install
# Install GDAL 3.4.1 #
######################
$> cd ~/postgis
$> curl http://download.osgeo.org/gdal/3.4.1/gdal-3.4.1.tar.gz | tar xzf -
$> cd gdal-3.4.1
$> ./configure --with-proj=/usr/local && make && sudo make install
# Install json-c-0.13 #
#######################
$> cd ~/postgis
$> mkdir json-c-build
$> git clone https://github.com/json-c/json-c.git
$> cd json-c
$> git checkout json-c-0.13
$> cd ../json-c-build
$> cmake ../json-c
$> make && sudo make install
# Install PostGIS 3.1.5 #
#########################
$> cd ~/postgis
$> curl https://download.osgeo.org/postgis/source/postgis-3.1.5.tar.gz | tar xzf -
$> cd postgis-3.1.5
$> ./configure \
--with-geosconfig=/usr/local/bin/geos-config \
--with-pgconfig=/usr/bin/pg_config \
--without-protobuf
$> make && sudo make install
# Add Library Path #
####################
$> sudo su -
$> echo "/usr/local/lib/" >> /etc/ld.so.conf.d/postgresql-pgdg-libs.conf
$> ldconfig
# Create Database with Extensions #
###################################
$> sudo su - postgres
$> psql -U postgres -c "CREATE DATABASE template_postgis IS_TEMPLATE true;"
$> psql -U postgres -d template_postgis \
-c "CREATE EXTENSION IF NOT EXISTS postgis; \
CREATE EXTENSION IF NOT EXISTS postgis_topology; \
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; \
CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder; \
CREATE EXTENSION IF NOT EXISTS pg_trgm; \
CREATE EXTENSION IF NOT EXISTS tablefunc;"
$> createdb -U postgres -T template_postgis exampledb
$> psql -U postgres -d exampledb -c "SELECT postgis_full_version();"
# Useful Links #
################
Compatibility Matrix -- https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment