1

I installed /bin/sh: wkhtmltopdf /usr/bin/ directory. However when I try to run the program by entering /usr/bin/wkhtmltopdf to shell I receive an error /bin/sh: /usr/bin/wkhtmltopdf: not found. It works, however, If I enter sh /usr/bin/wkhtmltopdf. Why is that and how can I fix it?

The permissions are ls -l:

-rwxr-xr-x 1 1000 1000 38.0M Nov 22 2016 wkhtmltopdf

type -a wkhtmltopdf : /usr/bin/wkhtmltopdf

Edit:

The OS I use is Alpine Linux

Output of ldd wkhtmltopdf:

/usr/bin # ldd wkhtmltopdf
    /lib64/ld-linux-x86-64.so.2 (0x7f88720cc000)
    /usr/lib/preloadable_libiconv.so => /usr/lib/preloadable_libiconv.so (0x7f8871fec000)
    libXrender.so.1 => /usr/lib/libXrender.so.1 (0x7f8871fe0000)
    libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x7f8871fa4000)
    libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x7f8871ef3000)
    libXext.so.6 => /usr/lib/libXext.so.6 (0x7f8871ee1000)
    libX11.so.6 => /usr/lib/libX11.so.6 (0x7f8871dbe000)
    libz.so.1 => /lib/libz.so.1 (0x7f8871da4000)
    libdl.so.2 => /lib64/ld-linux-x86-64.so.2 (0x7f88720cc000)
    librt.so.1 => /lib64/ld-linux-x86-64.so.2 (0x7f88720cc000)
    libpthread.so.0 => /lib64/ld-linux-x86-64.so.2 (0x7f88720cc000)
    libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f8871c4f000)
    libm.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f88720cc000)
    libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f8871c3b000)
    libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f88720cc000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by wkhtmltopdf)
    libexpat.so.1 => /usr/lib/libexpat.so.1 (0x7f8871c18000)
    libuuid.so.1 => /lib/libuuid.so.1 (0x7f8871c0f000)
    libbz2.so.1 => /usr/lib/libbz2.so.1 (0x7f8871c00000)
    libpng16.so.16 => /usr/lib/libpng16.so.16 (0x7f8871bd0000)
    libxcb.so.1 => /usr/lib/libxcb.so.1 (0x7f8871ba9000)
    libXau.so.6 => /usr/lib/libXau.so.6 (0x7f8871ba4000)
    libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x7f8871b9c000)
    libbsd.so.0 => /usr/lib/libbsd.so.0 (0x7f8871b88000)

I installed wkhtmltopdf by running the following commands in Docker:

 wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz && \
    tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz && \
    mv wkhtmltox/bin/wkhtmltopdf /usr/bin/ && mv wkhtmltox/bin/wkhtmltoimage /usr/bin
  • 1
    check the permissions of your file /usr/bin/wkhtmltopdf you probably don't have the executable bit. To change that: chmod +x /usr/bin/wkhtmltopdf – darxmurf Jun 3 at 7:30
  • -rwxr-xr-x 1 1000 1000 38.0M Nov 22 2016 wkhtmltopdf I tried that already but it looks like it's not a permissions error – Lau Jun 3 at 7:39
  • How did you install the program? – roaima Jun 3 at 7:43
  • 1
    Check the output of ldd wkhtmltopdf - you're probably missing a library – muru Jun 3 at 7:44
  • 1
    Please edit your question and i) show us the output of running wkhtmltopdf. Not sh wkhtmltopdf and not /usr/bin/wkhtmltopdf, just wkhtmltopdf. ii) tell us exactly how you installed it. iii) Show us the output of ls -l /usr/bin/wkhtmltopdf and iv) the output of type -a wkhtmltopdf. – terdon Jun 3 at 8:31
2

As indicated by ldd output, this wkhtmltopdf binary is built against glibc, the GNU C library:

libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f88720cc000)
Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by wkhtmltopdf)

The libc library implements the C standard library functions, as well as the POSIX API (libc.so.6), and the dynamic linker (ld-linux-x86-64.so.2). glibc is the most common libc implementation and used by most Linux distributions.

On Alpine Linux, musl-libc is used. musl is much more minimalistic in nature and aims for strong POSIX compliance. The library file for musl is libc.musl-x86_64.so.1, and the dynamic linker is ld-musl-x86_64.so.1. Programs linked against glibc will therefore fail to link against musl libc.

For running glibc programs on Alpine Linux, you're usually required to install glibc, as described here. In some cases, if only basic glibc compatibility is required, it is enough to install libc6-compat which is the musl-glibc compatibility package.

However, a better alternative is installing the corresponding Alpine package, if such is available (to my experience, in most cases, it is). In your case, simply install the wkhtmltopdf package (Alpine 3.9+): apk add wkhtmltopdf.

  • Thank you for informative answer. The package for glibc compatibility is libc6-compat not libc6-compact but I understand the confusion – Lau Jun 4 at 6:24
  • @Lau whops - thanks for correcting! Fixed – valiano Jun 4 at 6:29
  • Very strange I installed glibc from github, but it still compains wkhtmltopdf: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory However I can see that libXrender.so.1 exists – Lau Jun 4 at 7:00
  • I also tried to install using apk add wkhtmltopdf but that got a different error Cannot mix incompatible Qt library (version 0x50c03) with this library (version 0x50c00) Aborted (core dumped) Seems like I have another package that uses qt? is there a way to figure out which package uses it? – Lau Jun 4 at 7:04
  • @Lau for the Qt conflict, a naive way from the top of my head - if you could start from a fresh image then install the required packages one by one (if using a specific base image follow the steps in the Dockerfile), then see which package installs the conflicting Qt - then, remove it if not required – valiano Jun 4 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.