OpenStreetMap Server with Vagrant

Setting up vagrant

This is pretty easy. Just download vagrant and follow the setup instructions.

Let’s init our box:

vagrant box add ubuntu-13.10
vagrant init

Open your Vagrantfile (it will be auto-generated in the same folder you ran the first command) and change the content to

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config| = "ubuntu-13.10"
  config.vm.box_url = "" "forwarded_port", guest: 5430, host: 5432

Then start your vm for the first time. Your will reach your database on port 5432.

vagrant up

Install Postgres 9.3 and PostGIS

To install the latest version (9.3) we need to add the postgres debian repository.  This is done with

sudo sh -c 'echo "deb precise-pgdg main" >> /etc/apt/sources.list'
wget --quiet -O - | sudo apt-key add -
sudo apt-get update && sudo apt-get install Postgresql-9.3-postgis postgresql-contrib

Postgres should now be up and running and ready to be configured.

Installing osm2psql

There is a debian repository available to install osm2pqsl, which will install an older version of postgresql. We just remove the old version 🙂

sudo add-apt-repository ppa:kakrueger/openstreetmap
sudo apt-get update && sudo apt-get install osm2pgsql
# removing postgresql-9.1
sudo apt-get purge postgresql-9.1

Now we should configure the database to be ready for the osm import.

# Creating our user 'crossingworlds'
sudo su - postgres
createuser -d -E -i -l -P -r -s crossingworlds;

Creating users and extensions

sudo -u postgres psql
# psql (9.3.3)
CREATE DATABASE crossingworlds;
psql -h localhost -U crossingworlds

The Import

Download your osm file and use this command.

(A good source of osm-extracts can be found here)

osm2pgsql -s -d crossingworlds -U crossingworlds -H localhost -W -l --cache-strategy sparse --cache 128 oberbayern-latest.osm

We should take a closer look at all the commands used:

  • -s  : Slim mode for less memory consumption (no idea why this is not the default)
  • -d : The database we’ll be using
  • -U : The database User we generated earlier
  • -H : The host (localhost being the default value)
  • -W – password prompt
  • -l : Instructs the import to store geographical information in the Longitude/Latitude projection instead of the  “spherical 900913-projection” More information can be found : here
  • –cache-strategy sparse – lowers the memory consumption
  • –cache 128 – cache size in megabyte (vagrant has a default of 512MB RAM)


NOTE: Try importing a small osm file first, to see if the result is acceptable and fit to your needs. If you are planning on importing a large osm-file (e.g. a whole country) you should get yourself a big (and I am talking bathtub-big) cup of coffee since it might (depending on your machine) take quite a while to run the import. On our testserver, the import of Germany (~30GB osm file) took about 25 hours (4 cores, 6GB ram, standard HDD).

Database Access

In the end we need to open the database to access it via our host machine. Open the file


and add this line

host    all     all       md5

Restart the database to apply the settings

sudo service postgresql restart

You can now login to your database from within the virtual machine with

psql -h localhost -U crossingworlds

Write a Reply or Comment