How to get the MuPDF OpenGL viewer on Ubuntu 18.04?

TLDR

How do I install mupdf-gl on Ubuntu 18.04 (preferably without building from source)?


I have recently started using MuPDF. I tried installing it in a desktop machine with Ubuntu 18.04.3. However, I can only get the X11 version of it. I prefer the one that renders with OpenGL; that's the one I've been using on my laptop. I like it more, but also at this point I just want to know what I'm doing wrong, and learn to do it right :)

What I've done

I first installed MuPDF from the terminal with sudo apt install mupdf. Straightforward. But it wasn't what I expected: I immediately noticed that the keybindings were different.

I checked the version. It was MuPDF 1.12. The most recent version is 1.16. Thinking that might be it, I went looking how to install a more recent version.

I found this UbuntuHandbook post about installing version 1.13. I purged my installation, added their PPA, updated and reinstalled, which got me version 1.14. However, still no luck. When I ran mupdf it still behaved the same way.

Researching my issue, I saw some references to mupdf-gl and mupdf-x11 commands. So I dug among my files. I found that /usr/bin/mupdf runs /usr/lib/mupdf/mupdf-x11. But there's no mupdf-gl to be found.

At this point, I realize that my issue doesn't have to do with the version. Looking at MuPDF's release history I saw that the OpenGL viewer was rolled out on version 1.8.

I haven't tried building the library from source. From what I've seen, it doesn't appear that others are having the same issue installing through the repositories. I even found this Gentoo Forum post by someone who inadvertently was using the OpenGL viewer and was complaining about the old keybindings not working.

If it's relevant, running glxinfo | grep "OpenGL version" in my terminal yields OpenGL version string: 3.3 (Compatibility Profile) Mesa 19.2.8.

This my first post on any Stack Exchange, so any feedback on my format would be much appreciated.


Solution 1:

TL;DR

It is a Ubuntu packaging bug, it was already reported to launchpad as bug 1740105.

Compilation or installation from source

What do you need

The analysis of the PKGBUILD file from ArchLinux shows that muPDF needs freeglut, glu and mesa-libgl libraries for OpenGL.

On Ubuntu, the simulation of build-dependencies (by running apt-get build-dep with the -s flag) installs many OpenGL related packages (including the aforementioned):

$ sudo apt-get build-dep mupdf -s | grep Inst.*gl
Inst freeglut3 (2.8.1-3 Ubuntu:18.04/bionic [amd64])
Inst libglvnd-core-dev (1.0.0-2ubuntu2.3 Ubuntu:18.04/bionic-updates [amd64])
Inst libgles1 (1.0.0-2ubuntu2.3 Ubuntu:18.04/bionic-updates [amd64])
Inst libopengl0 (1.0.0-2ubuntu2.3 Ubuntu:18.04/bionic-updates [amd64])
Inst libglvnd-dev (1.0.0-2ubuntu2.3 Ubuntu:18.04/bionic-updates [amd64])
Inst libxcb-glx0-dev (1.13-2~ubuntu18.04 Ubuntu:18.04/bionic-updates [amd64])
Inst libgl1-mesa-dev (19.2.8-0ubuntu0~18.04.1 Ubuntu:18.04/bionic-updates [amd64])
Inst libglu1-mesa-dev (9.0.0-2.1build1 Ubuntu:18.04/bionic [amd64])
Inst freeglut3-dev (2.8.1-3 Ubuntu:18.04/bionic [amd64])

While the default installation of muPDF gives the following library dependencies:

$ ls /usr/lib/mupdf/mupdf* -1
/usr/lib/mupdf/mupdf-x11

$ ldd /usr/lib/mupdf/mupdf-x11 | grep -i gl
    libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f55297f6000)

so we do not have the OpenGL libraries shown in the previous list.

What to do on 18.04 LTS

To get OpenGL support we really need to

  • (a) recompile the package with build dependencies. So run:

    sudo apt-get build-dep mupdf mupdf-tools
    
    cd ~/Downloads
    apt-get source mupdf
    
    cd mupdf-1.12.0+ds1
    make
    sudo make install
    

    and you will get mupdf-gl compiled and installed into /usr/local/bin/mupdf-gl.

  • (b) use prebuilt package from the PPA, so you can install mupdf from there:

    sudo add-apt-repository ppa:cges30901/app
    sudo apt-get update
    sudo apt-get install mupdf
    

    and mupdf-gl will become available.

What to do on Ubuntu 20.04 LTS

Here exists the PPA, so you can install mupdf from there:

sudo add-apt-repository ppa:cges30901/app
sudo apt-get update
sudo apt-get install mupdf

and mupdf-gl will become available.

What to do when 22.04 LTS will be released

Nothing, simply install official package from repository, it ships mupdf-gl.

Solution 2:

This is still a problem in 20.04. To build a recent version, go to https://www.mupdf.com/downloads/index.html to find the latest source. Right now it's 1.18.0. Then

wget https://www.mupdf.com/downloads/archive/mupdf-1.18.0-source.tar.xz
tar xf mupdf-1.18.0-source.tar.xz
cd mupdf-1.18.0-source
sudo apt install mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev \
  xorg-dev libxcursor-dev libxrandr-dev libxinerama-dev freeglut3-dev
make
sudo make prefix=/usr/local install