Compiling Unzip for use on Heroku

I recently needed to unzip a file on Heroku. I attempted to use gunzip without success. I also tried tar but that didn’t work either. I needed unzip, but Heroku doesn’t include this in /bin on the dyno.

So I set out to compile a version of the binary on Heroku and add it to the bin directory of my app. Because the source itself was also a .zip I actually had to unzip the source on my local machine then create a tar ball that was guaranteed to decompress on the dyno. After I had my tar ball I uploaded it to s3 and did the following..

heroku run bash

curl -o /tmp/unzip.tar.gz ""

cd /tmp && tar zxvf unzip.tar.gz

cp /tmp/unzip610b/unix/Makefile /tmp/unzip610b/

cd /tmp/unzip610b && make generic

At this point you should have the unzip binary in your /tmp directory. I mv’d this file to a public folder in my app and curl’d my app for the file. Add this to your bin directory and you should have access to it as /app/bin is automatically in your path on a Heroku dyno.