We had some struggles making RGeo work on Heroku with GEOS extension. Web lacks of updated information about this topic, the purpose of this post is to collect existing information and update them.

Update! August, 14th 2019

Well, well, well… Apparently this buildpack does not work anymore.

It has been deprecated in favour of https://github.com/diowa/heroku-buildpack-vendorbinaries or Using RGeo with GEOS on Heroku with apt-get

Update! August, 13th 2019

Add a release rake tasks

Update! August, 1st 2017

Please take a look at the new article: Use RGeo with GEOS on Heroku via apt-get

Update! July, 1st 2016

BUILDPACK_URL was deprecated, so here it is a new approach.

1. Compile libraries (optional)

Take a look at Compile libraries on Heroku with Vesuvius and

2. Set up multiple buildpacks

We need to set LD_LIBRARY_PATH config variable to /app/lib and use the following buildpacks:

  1. https://github.com/diowa/heroku-buildpack-rgeo-prep.git

    Overwrites Heroku’s default .bundle/config to set BUNDLE_BUILD__RGEO to Heroku’s build directory

  2. https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git

    Allows us to vendor binaries into our project

  3. heroku/ruby

    The official Heroku Buildpack for Ruby, Rack, and Rails apps

We have a couple of way of achieving this:

Method 1: Using app.json

You need the following entries:

  "...": "",
  "env": {
    "...": "",
    "LD_LIBRARY_PATH": "/app/lib",
    "...": ""
  "...": "",
  "buildpacks": [
      "url": "https://github.com/diowa/heroku-buildpack-rgeo-prep.git"
      "url": "https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git"
      "url": "heroku/ruby"

Method 2: Using the console

$ heroku buildpacks:set https://github.com/diowa/heroku-buildpack-rgeo-prep.git
$ heroku buildpacks:add https://github.com/peterkeen/heroku-buildpack-vendorbinaries.git
$ heroku buildpacks:add heroku/ruby
$ heroku config:set LD_LIBRARY_PATH=/app/lib

3. Provide URLs of vendor libraries

Vendor Binaries buildpack expects a .vendor_urls file in the root of the repository containing publicly accessible URLs to the libraries compiled at step 1.

Here it is a working example:


Add this file to git and make sure it ends with a newline.

4. Deploy

Deploy to Heroku. Please note that if you have already installed rgeo, you need to recompile the gem.

Check the deploy log:

# bad
remote:        Using rgeo 0.6.0

# good
remote:        Installing rgeo 0.6.0 with native extensions

You can force recompiling in two ways:

  1. Downgrade to a previous version of rgeo (0.5.3), deploy, rollback, deploy again;
  2. Using the heroku repo plugin, running heroku repo:purge_cache -a appname and deploying again (recommended).

5. Check

You can check that everything is working by running heroku run console:

> RGeo::Geos.supported?
=> true

6. Optional Release task

You may be interested in checking that RGeo properly supports GEOS at deploy time. If something goes wrong, the deploy will fail.

Add a release entry to your Procfile:

release: bundle exec rails rgeo_supports_geos

Create a rake task:

# frozen_string_literal: true

desc 'Check if RGeo supports GEOS'
task :rgeo_supports_geos do
  abort 'Error: RGeo does not support GEOS.' unless RGeo::Geos.supported?

This guide could also be applied to proj.4. Take a look at our rgeo-prep buildpack if you need both libraries.


blog comments powered by Disqus