wiki:UsersWikiPostGIS21CentOS6pgdg

Version 3 (modified by Mike Taves, 10 years ago) ( diff )

use PostgreSQL 9.4 as example

How to install PostGIS 2.1 on CentOS 6 from packages

This installation method uses YUM packages maintained by Devrim GUNDUZ of the PostgreSQL Global Development Group (PGDG). For an overview of installing PostgreSQL using this method, see other details at http://wiki.postgresql.org/wiki/YUM_Installation.

Additional packages from EPEL 6 (Extra Packages for Enterprise Linux) are required to fulfill requirements for GDAL.

Configure YUM

Log into the system with root access. These instructions assume that you are using a command-line editor vi, however use whatever text utility you are comfortable with.

Open the first file for editing:

vi /etc/yum.repos.d/CentOS-Base.repo

On line 19, at the end of the [base] section, insert:

exclude=postgresql*

and near line 28 at the end of the [updates] section, insert again:

exclude=postgresql*

Save and close the file (with vi, press "esc" to go to command-mode, then type :wq).

Download and install PGDG RPM file

A PGDG RPM file needs to be downloaded for your platform and your PostgreSQL version requirements (you can choose the later). Find the correct RPM file for your system from here: http://yum.postgresql.org/repopackages.php

For example, if you have a 64-bit OS and want to install PostgreSQL 9.4:

curl -O http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm
rpm -ivh pgdg-centos94-9.4-1.noarch.rpm

A second repository, EPEL 6, is required for additional packages for GDAL. For all platforms, download the epel-release-6-8.noarch.rpm file from http://download.fedoraproject.org/pub/epel/6/i386/repoview/epel-release.html which will select your local mirror. Install the RPM:

curl -O http://<some mirror>/linux/fedora/fedora-epel/6/i386/epel-release-6-8.noarch.rpm # update this!
rpm -ivh epel-release-6-8.noarch.rpm

Install PostGIS

Install everything with:

yum install postgresql94-server postgis2_94

Now perform a few post-installation setup commands, in the order: (1) Initialize the database cluster (required), (2) start database (recommended, if you want to use it straight away), (3) allow it to start-up automatically on reboot (recommended):

service postgresql-9.4 initdb
service postgresql-9.4 start
chkconfig postgresql-9.4 on

Spatially enabling a database

Create a new database, e.g.:

[root@localhost ~]# su - postgres
-bash-4.1$ createdb postgis
-bash-4.1$ psql postgis
psql (9.4.0)
Type "help" for help.

postgis=# CREATE EXTENSION postgis;
CREATE EXTENSION
postgis=# SELECT PostGIS_full_version();
                                                                        postgis_full_version

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="2.1.0 r11822" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March2012" GDAL="GDAL 1.9.2, released 2012/10/08" LIBXML="2.7.6" LIBJSON="UNKNOWN" RASTER
(1 row)

To add topology support, a second extension can be created on the database:

CREATE EXTENSION postgis_topology;

Additional extensions

[root@localhost ~]# yum install postgresql94-contrib

will allow you to use more extensions. For example, you can activate the TIGER geocoder with:

postgis=# CREATE EXTENSION fuzzystrmatch;
CREATE EXTENSION
postgis=# CREATE EXTENSION postgis_tiger_geocoder;
CREATE EXTENSION
Note: See TracWiki for help on using the wiki.