Installing wkhtmltopdf on Ubuntu 14.04 and 16.04

Published on August 8, 2017 by

Installing wkhtmltopdf on Linux can be a bit tricky, especially for people who are not so familiar with *nix operating systems. There are various ways in which you can install wkhtmltopdf; use a package manager such as apt-get, compile from source, or download the pre-compiled binary file. We are going to be doing the latter in this tutorial.

Now the installation instructions for wkhtmltopdf have changed over the years, but as of this writing, the commands that you are about to see work for Ubuntu 14.04 and Ubuntu 16.04.

Installing wkhtmltopdf Dependencies

First, we need to install a couple of wkhtmltopdf dependencies.

apt-get install libfontconfig \
    zlib1g \
    libfreetype6 \
    libxrender1 \
    libxext6 \

Downloading & Extracting Archive

Then we will download and extract an archive containing the binary file. Be sure to update the link to use whichever version you prefer. You can find the links on the download page over at

curl -L -o wkhtmltopdf.tar.xz
tar -xf wkhtmltopdf.tar.xz

Moving Binary File & Permissions

Now we have a directory named wkhtmltox within our current working directory. This directory contains the binary file that we are looking for within the bin directory, namely wkhtmltopdf. We could just use that binary file from that directory as is, but we probably want to make wkhtmltopdf available throughout the system. To do that, we need to move it and give it permission to execute.

mv wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

Fixing SSL Bug

Now as of this writing, there is an issue causing you to see output similar to this when using wkhtmltopdf.

Loading pages (1/6)
QSslSocket: cannot resolve CRYPTO_num_locks                  ] 10%
QSslSocket: cannot resolve CRYPTO_set_id_callback
QSslSocket: cannot resolve CRYPTO_set_locking_callback
QSslSocket: cannot resolve sk_free
QSslSocket: cannot resolve sk_num

This relates to resolving SSL, so the solution is currently to downgrade libssl and
openssl. There may be other solutions, but this is what I found to be working. Now this is really not ideal, so hopefully it will be fixed soon. Until then, if you need to install wkhtmltopdf in a production setup, then please consider the implications of downgrading, such as security considerations.

Either way, here is how to fix the problem. Be sure to run the commands as root, e.g. with sudo.

For Ubuntu 14.04:

apt-get install openssl=1.0.1f-1ubuntu2
apt-get install libssl-dev=1.0.1f-1ubuntu2

For Ubuntu 16.04:

apt-get install libssl1.0.0=1.0.2g-1ubuntu4
apt-get install libssl-dev=1.0.2g-1ubuntu4

Running wkhtmltopdf now, the above errors should go away and everything should be working.

Testing wkhtmltopdf

You can test if wkhtmltopdf is working as intended by generating a PDF file with contents of

wkhtmltopdf google.pdf

I will try to stay up to date with any changes, but these things change quite often. So if the above does not work out for you, please let me know in the comments.

Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

4 comments on »Installing wkhtmltopdf on Ubuntu 14.04 and 16.04«

  1. Romain

    Thanks for this really well explained blog post. It worked like a charm.


  2. Marie

    Hello I have to do this on Ubuntu 16.04.3 LTS

    sudo apt-get install libssl-dev=1.0.2g-1ubuntu4.10

    instead of

    apt-get install libssl1.0.0=1.0.2g-1ubuntu4.8

    thank you again :)

  3. Vikas

    Thanks Marie, it worked.

  4. Joe

    I had trouble finding the exact last digit for different servers and found that omitting it worked in all scenarios I tried.

    sudo apt-get install libssl-dev=1.0.2g-1ubuntu4
  5. Laurent Cetinsoy

    Thanks for the blog and thanks Marie for the last workaround !

Leave a Reply

Your e-mail address will not be published.