> > > How to Install PostgreSQL 9.2 + PostGIS 2.0 in Ubuntu

How to Install PostgreSQL 9.2 + PostGIS 2.0 in Ubuntu

install postgresql 9.2Though PostgreSQL 9.3 has released, there are people who still uses PostgreSQL 9.2 in combination with PostGIS 2.0. It is fairly easy to install and set-up PostgreSQL 9.2 in Ubuntu. It can be done in no time using any package manager like aptitude or synaptic. But the PostGIS 2.0 version available in apt repository has some compatibility problems and it is hard to install(at least for me). So in this post we will try the alternate way – install from source. So let’s start with the PostgreSQL 9.2 installation.

1. Install PostgreSQL 9.2

  1. Find out your Ubuntu release
    Run the following command in your terminal to get your Ubuntu release name(codename).

    lsb_release -c

    You will get something like precise (in my case) or wheezy. Make a note of it.

  2. Add PostgreSQL repository to source list
    In the following command replace the codename with the release name, which you got from step 1, and run.

    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ codename-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
  3. Import PostgreSQL repository key
    Use the following command to import the repository key:

    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  4. Install PostgreSQL 9.2
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get -y install python-software-properties
    sudo apt-get install postgresql-9.2 pgadmin3

2. Install PostGIS 2.0

Now it is time to install PostGIS 2.0.6. Prior to build and install PostGIS it is better to build GEOS, which is required for PostGIS raster topology.

  1. Build GEOS 3.3.9
    The following commands will download make and install the GEOS 3.3.9. Run it one by one.

    wget http://download.osgeo.org/geos/geos-3.3.9.tar.bz2
    tar xfj geos-3.3.9.tar.bz2
    cd geos-3.3.9
    sudo make install
  2. Build PostGIS 2.0.6
    Run the following commands in your home folder.

    wget http://download.osgeo.org/postgis/source/postgis-2.0.6.tar.gz
    tar xfz postgis-2.0.6.tar.gz
    cd postgis-2.0.6
    sudo make install
    sudo ldconfig
    sudo make comments-install

3. Set Up PostgreSQL to use with PgAdmin

You may follow the step 4 and 5 of the following post to make necessary settings so that you can access your server using PgAdmin3: Accessing Database from Terminal/pgAdmin

4. Enable PostGIS for the Database

Now that we have made all the necessary installations and configurations, let’s to try to enable PostGIS to your postgis Databae.

  1. Connect to your server and open a query browser and execute:
  2. Run the following function to verify that PostGIS is installed correctly:
    SELECT postgis_version();

    It will return something like:

So, we finished with Installation of PostgreSQL 9.2 with PostGIS 2.0. In case of any problems please leave a comment here!

The following two tabs change content below.

Vipin Raj

Vipin Raj is a software developer specialized in PostgreSQL Database and Data Modeling, the man behind technobytz and an IoT and Security enthusiast. Having 3+ years of experience in the IT industry, he is currently pursuing his masters in computer science and information security. He spend his free time writing blog posts with the intension of sharing his knowledge to the tech community.

One thought on “How to Install PostgreSQL 9.2 + PostGIS 2.0 in Ubuntu

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.