How do I install GDAL on Heroku?

Issue

My app requires gdal libraries installed in the OS in order to work

Resolution

There are two options for getting these libraries installed on your dyno:

heroku-buildpack-apt

This buildpack adds support for installing packages from apt during build. You can add it to your project by following these steps:

Add the buildpack:

$ heroku buildpacks:add --index 1 heroku-community/apt

Create a file in your application root called Aptfile with the gdal dependency:

Aptfile

gdal-bin

Commit and deploy:

$ git add Aptfile  
$ git commit -m "Add apt dependency"
$ git push heroku master
...
$ heroku run bash  
Running bash on  morning-plains-93483... up, run.2593 (Free)
~ $ which ogr2ogr
/app/.apt/usr/bin/ogr2ogr

Switch build systems

Heroku has a new build system in developer preview that allows installation of apt packages as a first-class experience: https://devcenter.heroku.com/articles/buildpack-builds-heroku-yml

You can switch to this by doing the following:

$ heroku update beta
$ heroku plugins:install @heroku-cli/plugin-manifest
$ heroku manifest:create
$ heroku stack:set container

Add gdal-bin under build: packages: in the generated heroku.yml:

setup:
  config: {}
build:
  packages:
    - gdal-bin
  languages:
    - nodejs
run:
  web: node src/index.js

Deploy:

$ git add heroku.yml
$ git commit -m "Add heroku.yml"
$ git push heroku master
...
$ heroku run bash
Running bash on  morning-plains-93483... up, run.6417 (Free)
~ $ ls
Dockerfile  Procfile  README.md  app.json  heroku.yml  node_modules  package-lock.json  package.json  src
~ $ which ogr2ogr
/usr/bin/ogr2ogr

Ask on Stack Overflow

Engage with a community of passionate experts to get the answers you need

Ask on Stack Overflow

Heroku Support

Create a support ticket and our support experts will get back to you

Contact Heroku Support