[[TOC()]] = !GeoDjango Ubuntu Installation with Apt-get= The GeoDjangoInstall wiki describes in detail how to install GeoDjango dependencies from '''source'', which for many reasons is a great approach. However, with the recent Ubuntu releases you can also use the '''Synaptic Package Manager''' (`apt-get install` on the command line) to handle the installation work for you. * Note: if you take this route, be advised that the location of install directories will differ significantly from the source install approach. ie. PostGIS will be installed inside the PostgreSQL contrib and share directories specific to the PostgreSQL version number. == Short Version == * Install Django from trunk * Add the Ubuntu universe and multiverse debs * Update and upgrade Ubuntu with Apt-get * Easy_install Pycopg2 * If you need Postgres and Apache apt-get them * make sure to grab the dev versions * edit pg_hba.conf to allow django connections * Apt-get postgis, libgdal, libgeos, and proj * Create your PostGIS enabled PostgreSQL db * Proceed with writing your first GeoDjango app * Sample apps for !GeoDjango at: [http://code.google.com/p/geodjango-basic-apps/ geodjango-basic-apps] == Full Instructions == === Step 1 === Add the universe and multiverse debian repositories {{{ #if you have the desktop edition sudo gedit /etc/apt/sources.list #if you have the server edition sudo nano /etc/apt/sources.list # if you know how to use vim, you probably don't need to be reading this page! sudo vim /etc/apt/sources.list ## Add these Universe / Multiverse sites to the bottom of the page ## Make sure to specify the correct Ubuntu version deb http://archive.ubuntu.com/ubuntu gutsy universe multiverse deb-src http://archive.ubuntu.com/ubuntu gutsy universe multiverse deb http://archive.ubuntu.com/ubuntu gutsy-security universe multiverse deb-src http://archive.ubuntu.com/ubuntu gutsy-security universe multiverse deb http://archive.ubuntu.com/ubuntu gutsy-updates universe multiverse deb-src http://archive.ubuntu.com/ubuntu gutsy-updates universe multiverse }}} === Step 2 === Then upgrade and update ubuntu based on these new sources {{{ apt-get update apt-get upgrade }}} === Step 3 === Use easy_install to install psycopg2 {{{ wget http://peak.telecommunity.com/dist/ez_setup.py sudo python ez_setup.py sudo easy_install psycopg2 }}} === Step 4 === Install Apache and PostgreSQL (if you need them) {{{ apt-get install apache2 apache2-threaded-dev apache2-doc apache2-mpm-prefork apache2-utils ssl-cert }}} {{{ sudo apt-get install postgresql postgresql-contrib postgresql-server-dev-8.3 # or -8.2 }}} * Then make sure that the postgresql programs are on your path or in .bash_profile {{{ Export PATH=/usr/lib/postgresql/8.3/bin/ }}} * Open up access in the pg_hba.conf file {{{ sudo vim /etc/postgresql/8.2/main/pg_hba.conf # change ident sameuser to trust - WARNING SECURITY RISK # comment out this line to allow, for instance, to django/psycopg2 to connect without password local all postgres ident sameuser }}} * Restart the server by switching into the default user {{{ sudo su - postgres pg_ctl -o -i -D /var/lib/postgresql/8.3/main/ restart }}} === Step 5 === Apt-get install postgis, libgdal, libgeos, and proj * Note: search for the exact package names with {{{ apt-cache search GIS_LIB_NAME }}} {{{ apt-get install postgresql-8.2-postgis libgeos-dev libgeos-c1 libgdal1-dev proj }}} === Step 6 === Create your PostGIS `template_postgis` database {{{ # Switch to the default postgres user sudo su - postgres # Create a template database with UTF encoding owned by the postgres user (or your user of choice) createdb -E UTF8 -O postgres -U postgres template_postgis # Now you can switch back to your normal user exit # Load the required procedural language for postgis createlang plpgsql -d template_postgis -U postgres }}} Now you are ready to actually load the postgis functions and tables as sql inserts * Note: the two postgis sql files (lwpostgis.sql and spatial_ref_sys.sql) were likely installed in the postgres share directory {{{ pg_config --sharedir # will give you that dir # Also look in: ls /usr/share/ # or /usr/local/share/ }}} Try: {{{ psql -d template_postgis -U postgres -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql # Note: ignore any NOTICES, like 'psql:/usr/share/lwpostgis.sql:44: NOTICE: type "histogram2d" is not yet defined' }}} * You should see output like: {{{ BEGIN CREATE FUNCTION CREATE OPERATOR [...] CREATE TYPE CREATE AGGREGATE COMMIT }}} * If you get an error about not being able to find `geos` add /usr/local/lib to /etc/ld.so.conf and run: {{{ ldconfig # Then restart PostgreSQL }}} Then load the geographic projections table: {{{ psql -d template_postgis -U postgres -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql }}} Whoa! Hopefully that worked, and you will only have to do it once! From then on create a PostGIS database like: {{{ createdb -U postgres -T template_postgis DB_NAME }}} === Step 7 === Return to GeoDjangoInstall for troubleshooting and tests for GDAL and GEOS (see bottom of page) === Step 8 === Check out [http://mapserver.gis.umn.edu/ MapServer], [http://mapnik.org/ Mapnik], and [http://openlayers.org/ OpenLayers], open source mapping applications recommended for use with !GeoDjango. Install these and a few other helpful utilities with: {{{ sudo apt-get install cgi-mapserver mapserver-bin python-gdal python-mapscript gdal-bin }}}