Here it is a new, super-easy approach to use Rgeo with GEOS on Heroku, by using the amazing heroku-buildpack-apt buildpack.

1. Add Aptfile

At the root of your repository, add a file called Aptfile with the following content:

libproj-dev
libgeos-dev

Make sure it ends with a newline.

2. Add the heroku-buildpack-apt buildpack

Method 1: Using app.json

You need to add the following entries:

  "buildpacks": [
    {
      "url": "https://github.com/heroku/heroku-buildpack-apt"
    },
    {
      "url": "heroku/ruby"
    }
  ]

Method 2: Using the console

$ heroku buildpacks:add --index 1 https://github.com/heroku/heroku-buildpack-apt

3. 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 by using the heroku repo plugin, running heroku repo:purge_cache -a appname and deploying again.

4. Check

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

> RGeo::Geos.supported?
=> true

Notes

An APT package may not be up to date with the latest version of the library it includes. In the before example, you will get GEOS 3.5.0, but (at the moment I’m writing) version 3.6.2 is out.

If you need newer versions of your libraries, you could use the following approach: Compile libraries on Heroku with Vesuvius.

References


blog comments powered by Disqus