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 \ libx11-6
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 wkhtmltopdf.org.
curl -L -o wkhtmltopdf.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.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
You can test if wkhtmltopdf is working as intended by generating a PDF file with contents of google.com.
wkhtmltopdf https://www.google.com 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.