Installing and Configuring PostgreSQL and PostGIS on Amazon Linux

A step by step tutorial on installing and configuring PostgreSQL and PostGIS on an Amazon EC2 instance running Amazon Linux AMI. The procedure has been tested on Amazon Linux AMI, but should also apply in general to Fedora/Red Hat/CentOS distributions.


1. Install Linux updates, set time zones, followed by GCC and Make

sudo yum -y update
sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \
sudo yum install -y gcc make gcc-c++


2. Install Readline and zlib libraries

sudo yum -y install readline-devel
sudo yum -y install zlib-devel


3. Download and Install PostgreSQL database server

bzip2 -d postgresql-9.2.2.tar.bz2
tar -xf postgresql-9.2.2.tar
cd postgresql-9.2.2
sudo gmake install


4. Configure PostgreSQL database server

Create User:

sudo adduser postgres
sudo passwd postgres
<Enter Password>
sudo mkdir /usr/local/pgsql/data
sudo chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

If you get a ‘There are stopped jobs’ message:



5. Add Soundex ability

cd /home/ec2-user/postgresql-9.2.2/contrib/fuzzystrmatch
sudo make install


6. Login to PostgreSQL

su - postgres
Password:<type your password set in 4 above>
psql (9.2.2)


7. Make a directory for PostGIS

cd /home/ec2-user/
mkdir postgis cd postgis


8. Download and Install requirements for PostGIS Installation

a. Get Proj4 reprojection library (version 4.6.0 or greater)

gzip -d proj-4.8.0.tar.gz
tar -xvf proj-4.8.0.tar
cd proj-4.8.0
sudo make install


b. GEOS geometry library (version 3.2.2 or greater)

cd /home/ec2-user/postgis
bzip2 -d geos-3.3.7.tar.bz2
tar -xvf geos-3.3.7.tar
cd geos-3.3.7 ./configure make sudo make install 


c. LibXML2, (version 2.5.x or higher)

sudo yum -y install libxml2-devel


d. JSON-C, (version 0.9 or higher)

cd /home/ec2-user/postgis
gzip -d json-c-0.9.tar.gz
tar -xvf json-c-0.9.tar
cd json-c-0.9
sudo make install


e. GDAL, (version 1.6 or higher)

cd /home/ec2-user/postgis
gzip -d gdal-1.9.2.tar.gz
tar -xvf gdal-1.9.2.tar
cd gdal-1.9.2
sudo make install


9. Update Libraries

sudo su
echo /usr/local/lib >> /etc/


10. PostGIS installation

cd /home/ec2-user/postgis
gzip -d postgis-2.0.3SVN.tar.gz
tar -xf postgis-2.0.3SVN.tar
cd postgis-2.0.3SVN
./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-raster
sudo make install


11. Build PostGIS Extensions and Deploy

cd extensions/postgis
make clean
sudo make install
cd ..
cd postgis_topology
make clean
sudo make install

If this tutorial was helpful to you, then please do not forget to leave a comment, or two. :)

  • asdf

    [root@oragis postgis-2.0.3SVN]# cd extensions/postgis/

    [root@oragis postgis]# make

    make: *** No rule to make target `../../postgis/postgis.sql’, needed by `sql_bits/postgis.sql’. Stop.

    • saxenap

      Hello asdf,

      I have fixed some of the steps above and tested them on an EC2 server with no errors. If you tried the steps again, they should work with no problems at all.

      Good luck!

      • Chris

        Hello saxenap,
        The Tutorial is great so far. But I get the same output as asdf. Any advise?
        Thanks for the great work!

      • Chris

        I tried again, now my output is the following:

        [ec2-user@ip-10-224-113-132 postgis]$ make clean

        /bin/sh: /var/lib/jenkins/workspace/pg/rel/pg9.0w64/bin/pg_config: No such file or directory

        make: /var/lib/jenkins/workspace/pg/rel/pg9.0w64/bin/pg_config: Command not found

        make: *** No rule to make target `clean’. Stop.

        [ec2-user@ip-10-224-113-132 postgis]$

        greetings Chris

  • Mike Carson

    in case it helps anyone else- I was having an issue with “./configure …” in step 10 with “geos-config” not found. I had to first do:

    # export PATH=/usr/local/bin:$PATH

    and then

    # ./configure –with-pgconfig=/usr/local/pgsql/bin/pg_config –with-raster

    # make

    # make install

  • liblib


    trying to do step 10 command

    ./configure –with-pgconfig=/usr/local/pgsql/bin/pg_config –with-raster

    i get the following warnings

    configure: WARNING: ImageMagick does not seem to be installed. Documentation cannot be built
    configure: WARNING: dblatex is not installed so PDF documentation cannot be built
    configure: WARNING: could not locate Docbook stylesheets required to build the documentation
    configure: WARNING: could not locate CUnit required for unit tests

    that end up with the error:

    configure: error: could not find geos-config within the current path. You may need to try re-running configure with a –with-geosconfig parameter.

    I installed ImageMagick using the command: yum install ImageMagick

    this removed the first warning but kept all the rest, as well as the error,
    Any help will be greatly appreciated

  • furcon

    thanks doc that was quite helpful …