Skip to content

Instantly share code, notes, and snippets.

@arthur-e arthur-e/
Last active May 25, 2019

What would you like to do?
Ubuntu for GIS Installation and Setup

Post-Installation Fixes and Setup

# Install compilers and linking tools; other tools
sudo apt-get install g++ swig curl build-essential python-all-dev

# Install package manager
sudo apt-get install synaptic

# Install Unity customization tool
sudo apt-get install unity-tweak-tool

# If the hardware brightness controls don't work, use:
sudo add-apt-repository ppa:indicator-brightness/ppa
sudo apt-get update && sudo apt-get install indicator-brightness

# Allows use of easy_install and, later, pip
sudo apt-get install python-setuptools

# Allows the installation of some Python packages (e.g. psycopg2) in a virtual environment with pip
sudo apt-get install libpq-dev python-dev

# Python IDE
sudo apt-get install ipython

# gedit plugins
sudo apt-get install gedit-plugins gedit-developer-plugins

Installed Packages

  • Apache (v2.2)
  • GDAL (v1.9.2)
  • GDAL Utilities (GDAL-OGR, v1.9.2)
  • GEOS
  • Git
  • Mercurial
  • MongoDB
  • Node.js
  • pgAdmin3
  • PostgreSQL (9.1)
  • PostGIS (2.1)
  • Proj
  • psycopg2
  • R
  • virtualenv


Upgrading GEOS can break existing Django projects! Here is the solution.

# SWIG required to install Python bindings
sudo apt-get install swig swig2.0

# It's necessary to compile from source for 13.10
cd /usr/local/ && sudo mkdir geos && sudo chown arthur geos && cd geos
tar -xvf geos-3.4.2.tar.bz2 && rm geos-3.4.2.tar.bz2 && cd geos-3.4.2
./configure --enable-python
sudo make install


# It's necessary to compile from source for 13.10
cd /usr/local/ && sudo mkdir proj && sudo chown arthur proj && cd proj
tar -xzvf proj-4.8.0.tar.gz && rm proj-4.8.0.tar.gz && cd proj-4.8.0
sudo make install


sudo apt-get install libhdf4-0 libhdf4-dev


# Install MPI compiler for parallel HDF5 installation
sudo apt-get install libcr-dev mpich2 mpich2-doc

cd /usr/local/ && sudo mkdir hdf5 && sudo chown arthur hdf5 && cd hdf5
tar -xzvf hdf5-1.8.13.tar.gz && rm hdf5-1.8.13.tar.gz && cd hdf5-1.8.13

# For parallel HDF5 support (may not work with GDAL)
CC=/usr/bin/mpicc ./configure --prefix=/usr/local --enable-shared --enable-hl
sudo make install


# To install from packages...
sudo apt-get install gdal-bin python-gdal

# Development files and headers for GDAL
sudo apt-get install libgdal-dev libgdal1-dev

Installing GDAL in a Virtual Environment

# For a virtual environment... (
cd /usr/local/pythonenv/my-virutal-environment/
source bin/activate
pip install --no-install gdal && cd gdal
python build_ext --gdal-config=/usr/bin/gdal-config --libraries=gdal --include-dirs=/usr/include/gdal/
cd .. && pip install --no-download gdal

Compiling GDAL from Source

# Compile GDAL from source...
cd /usr/local/ && sudo mkdir gdal && sudo chown arthur gdal && cd gdal
tar -xzvf gdal-1.11.0.tar.gz && rm gdal-1.11.0.tar.gz && cd gdal-1.11.0
./configure --with-python --with-hdf5=/usr/local/hdf5/hdf5-1.8.13/hdf5
sudo make install


# Install from apt-get
sudo apt-get install postgresql-9.3 postgresql-client-9.3 postgresql-client-common postgresql-common pgadmin3

# If building PostGIS from source or if missing the makefile...
sudo apt-get install postgresql-server-dev-9.3

# Define superuser(s)
sudo su -c "createuser arthur --login --inherit --superuser --createdb --createrole --pwprompt" - postgres
sudo service postgresql restart

# If using PostgreSQL for Python projects, it is necessary to install...
sudo apt-get install python-psycopg2


PostGIS requires the following libraries:

  • GEOS (libgeos)
  • Proj (libproj)
  • GDAL (libgdal)

To install PostGIS from source:

# Install dependencies
sudo apt-get install libxml2-dev

cd /usr/local/ && sudo mkdir postgis && sudo chown arthur postgis && cd postgis
tar -xzvf postgis-2.1.4.tar.gz && rm postgis-2.1.4.tar.gz && cd postgis-2.1.4
sudo ./configure --with-projdir=/usr/local/proj/proj-4.8.0/
sudo make install

# Configure template database
sudo su -c "createdb $POSTGIS_TEMPLATE" - postgres
sudo -u postgres psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='$POSTGIS_TEMPLATE';"
sudo -u postgres psql -d $POSTGIS_TEMPLATE -f /usr/share/postgresql/$POSTGRESQL_VER/contrib/postgis-2.1/postgis.sql
sudo -u postgres psql -d $POSTGIS_TEMPLATE -c "GRANT ALL ON geometry_columns TO PUBLIC;"
sudo -u postgres psql -d $POSTGIS_TEMPLATE -c "GRANT SELECT ON spatial_ref_sys TO PUBLIC;"

To create a new superuser in PostgreSQL:

sudo su -c "createuser arthur --login --inherit --superuser --createdb --createrole --pwprompt" - postgres

The shp2pgsql and raster2pgsql binaries may not be on your path after the install. To remedy this:

# Put the loader `shp2pgsql` on your path; likely not done when building from source
cd /usr/local/postgis/postgis-2.1.4/loader
sudo make install
sudo ln -s /usr/local/postgis/postgis-2.1.4/loader/shp2pgsql /usr/local/bin/shp2pgsql

# Link to the `raster2pgsql` binary
sudo ln -s /usr/lib/postgresql/9.3/bin/raster2pgsql /usr/bin/raster2pgsql
sudo ldconfig


sudo apt-get install r-base

My favorite packages for R include:

install.packages(c('plyr', 'reshape2', 'ggplot2', 'knitr', 'sp', 'raster'))
install.packages('rgdal') # Only if GDAL is installed


sudo apt-get install apache2 apache2-bin apache2-data apache2-mpm-worker

# WSGI module
sudo apt-get install libapache2-mod-wsgi

# Activate modules that were not activated at installation
sudo a2enmod proxy proxy_http rewrite


sudo apt-get install git

To connect to GitHub, you need to generate SSH keys...

# Generating SSH keys for GitHub
mkdir -p ~/.ssh/ && cd ~/.ssh/
ssh-keygen -t rsa -C ""
# Hit "Enter" to use defaults

# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)
sudo apt-get install xclip

# Copies the contents of the file to your clipboard; add to your account on
xclip -sel clip < ~/.ssh/

# Setting global configs
git config --global "K. Arthur Endsley"
git config --global
git config --global core.editor nano
git config --global merge.tool vimdiff
git config --global github.user arthur-e
git config --global color.ui true
git config --global alias.pushall "push --recurse-submodules=on-demand" # Recursively check submodules in a push

# Converts all Windows CR-LF line endings to Unix LF line endings on commit
git config --global core.autocrlf input

To configure a repository to have multiple remotes to push to simultaneously:

git remote rm origin
git remote add origin [path/to/network/repo]
git config --add remote.origin.url


sudo apt-get install mercurial


sudo apt-key adv --keyserver --recv 7F0CEB10

# Create a /etc/apt/sources.list.d/10gen.list file and include the following line for the 10gen repository.
echo 'deb dist 10gen' | sudo tee /etc/apt/sources.list.d/10gen.list

sudo apt-get update && sudo apt-get install mongodb-10gen


sudo mkdir /usr/local/nodejs && sudo chown arthur /usr/local/nodejs && cd /usr/local/nodejs
tar -xzvf node-v0.10.24.tar.gz && rm node-v0.10.24.tar.gz && cd node-v0.10.24
sudo make
sudo make install

Python Virtual Environments

sudo easy_install pip
sudo pip install virtualenv
sudo mkdir /usr/local/pythonenv
sudo chown arthur /usr/local/pythonenv

Using Django in a Virtual Environment

The latest versions of Django require a particular setup in the file.

import sys, os, site

# Virtual environment setup


# Remember original sys.path
prev_sys_path = list(sys.path)

for directory in ALLDIRS:

# Reorder sys.path so new directories are at the front
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:

sys.path[:0] = new_sys_path

# End setup

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
os.environ['DJANGO_SETTINGS_MODULE'] = 'scour_server.settings'
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'scour_server.settings')

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()


Because we built GDAL from source, it is necessary to bypass the automatic installation of the gdal-bin package. The Python bindings should also be bypassed, as GDAL should have been built --with-python support.

sudo apt-get install --no-install-recommends qgis qgis-plugin-grass

If GDAL was not built from source and was instead installed as a package, QGIS can also be easily installed as a package:

# This would install `qgis` from the package manager:
# sudo apt-get install qgis python-qgis qgis-plugin-grass


# Requires Node.js and NPM
sudo npm install -g topojson

# Install the geojson-cli
sudo npm install -g geojson

Python Virtual Environments (virtualenv)

sudo easy_install pip
sudo pip install virtualenv


sudo apt-get install texlive-base texlive-latex-base texlive-extra-utils texlive-math-extra

# Or...
sudo apt-get install texlive-full
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.