Skip to content

Instantly share code, notes, and snippets.

@rolo
Created December 15, 2011 13:44
Show Gist options
  • Star 73 You must be signed in to star a gist
  • Fork 37 You must be signed in to fork a gist
  • Save rolo/1481128 to your computer and use it in GitHub Desktop.
Save rolo/1481128 to your computer and use it in GitHub Desktop.
Install Postgres 9.1, PostGIS and create PostGIS template on Ubuntu 11.10 Oneiric Ocelot
#!/bin/bash
#
# Install Postgres 9.1, PostGIS and create PostGIS template on a clean Ubuntu 11.10 Oneiric Ocelot box
# http://wildfish.com
# add the ubuntu gis ppa
sudo apt-get -y install python-software-properties
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
# the big list of apt dependencies to check we have installed
sudo apt-get -y install postgis postgresql-9.1 postgresql-server-dev-9.1 postgresql-contrib-9.1 postgis gdal-bin binutils libgeos-3.2.2 libgeos-c1 libgeos-dev libgdal1-dev libxml2 libxml2-dev libxml2-dev checkinstall proj libpq-dev
sudo mkdir -p '/usr/share/postgresql/9.1/contrib/postgis-1.5'
# fetch, compile and install PostGIS
wget http://postgis.refractions.net/download/postgis-1.5.3.tar.gz
tar zxvf postgis-1.5.3.tar.gz && cd postgis-1.5.3/
sudo ./configure && sudo make && sudo checkinstall --pkgname postgis-1.5.3 --pkgversion 1.5.3-src --default
# now create the template_postgis database template
sudo su postgres -c'createdb -E UTF8 -U postgres template_postgis'
sudo su postgres -c'createlang -d template_postgis plpgsql;'
sudo su postgres -c'psql -U postgres -d template_postgis -c"CREATE EXTENSION hstore;"'
sudo su postgres -c'psql -U postgres -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql'
sudo su postgres -c'psql -U postgres -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql'
sudo su postgres -c'psql -U postgres -d template_postgis -c"select postgis_lib_version();"'
sudo su postgres -c'psql -U postgres -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"'
sudo su postgres -c'psql -U postgres -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"'
sudo su postgres -c'psql -U postgres -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;"'
echo "Done!"
@avances123
Copy link

hello rolo, in oneiric i think we have postgis 1.5.3 in the main repo:

$ apt-cache policy postgresql-9.1-postgis
postgresql-9.1-postgis:
Instalados: 1.5.3-1
Candidato: 1.5.3-2oneiric1
Tabla de versión:
1.5.3-2
oneiric1 0
500 http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu/ oneiric/main amd64 Packages
*** 1.5.3-1 0
500 http://es.archive.ubuntu.com/ubuntu/ oneiric/universe amd64 Packages
100 /var/lib/dpkg/status

@rolo
Copy link
Author

rolo commented Dec 30, 2011

That's sure easier. Nice one - will update. Thanks.

@Horki
Copy link

Horki commented Feb 1, 2012

"
ivan@ivan-Inspiron-N5110:~/postgis-1.5.3$ sudo su postgres -c'createdb -E UTF8 -U postgres template_postgis'
Password:
createdb: could not connect to database postgres: fe_sendauth: no password supplied
"
Please can you tell me what the password is , or how to found it out?
my e-mail: ivanzvonimirhorvat@gmail.com

@Tab3r
Copy link

Tab3r commented Mar 14, 2012

I think the script need to update pg_database table, with something like that:

sudo su postgres -c'psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis';"'

So, the table is marked as a template.

@paulovianna
Copy link

Thanks!!!

Copy link

ghost commented Feb 5, 2013

Incase of "ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/hstore.control": No such file or directory"

run sudo apt-get install postgresql-contrib

Thanks to https://gist.github.com/terryjray/3296171

@JuanDaniel
Copy link

Thank, really this post helped me.

@striveforbest
Copy link

Unpacking postgis-1.5.3 (from .../postgis-1.5.3_1.5.3-src-1_amd64.deb) ...
dpkg: error processing /home/tspxyz/postgis-1.5.3/postgis-1.5.3_1.5.3-src-1_amd64.deb (--install):
trying to overwrite '/usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql', which is also in package postgresql-9.1-postgis 1.5.3-2
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
/home/tspxyz/postgis-1.5.3/postgis-1.5.3_1.5.3-src-1_amd64.deb

@beshur
Copy link

beshur commented Feb 24, 2014

Hi!

Do you have libgeos-3.2.2 downloading ok?
I get an error.

@SumitMunot
Copy link

Thanks!!!

@localdrive
Copy link

THX A LOT MAN !!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment