Install Chromium on Ubuntu 19.10+ from Debian instead of snap

As you might know, Ubuntu starting from 19.10 now ships with Chromium as a snap with no option to install it as a deb package. IMO, snap is still not polished enough to become default, having drawbacks like slow app first startup, integration issues sometimes, etc. I hope some day it will shine, but until then, users have to have a choice.

I get Ubuntu devs arguments: stop wasting too much time to package for different Ubuntu versions with different tools and dependencies — better package once and use this time/resources in more productive ways. But there are other ways of achieving this, rather than going snap-only, like use package from Debian verbatim (you know, like it's done with 99% of packages in Ubuntu).

So that's exactly what we're going to do: use package from Debian.

I know, I know: Ubuntu devs don't recommend to use packages from Debian. Well, you know what, I don't recommend Ubuntu devs to force Calculator that takes 5 seconds to start from SSD on their users. Anyway, we are going to configure apt to never install anything from Debian repos except for Chromium and a couple of dependencies not available in Ubuntu.

  1. Set preferences for Debian repos in general and Chromium package in particular:

    sudo tee -a /etc/apt/preferences.d/chromium.pref <<EOF
    Package: *
    Pin: origin "deb.debian.org"
    Pin-Priority: -10
    
    Package: chromium* libvpx5 libjpeg62-turbo
    Pin: origin "deb.debian.org"
    Pin-Priority: 999
    EOF
    

  2. Add Debian repos:

    sudo tee -a /etc/apt/sources.list.d/debian.list <<EOF
    deb http://deb.debian.org/debian/ stable main #Debian stable
    deb http://deb.debian.org/debian/ stable-updates main #Debian updates
    deb http://deb.debian.org/debian-security stable/updates main #Debian security updates
    EOF
    

  3. Install Debian signing keys:

    sudo apt install debian-archive-keyring && \
    sudo apt-key add /usr/share/keyrings/debian-archive-keyring.gpg
    

  4. Update package lists: sudo apt update
    First update will take some time, as it needs to download about 50MB of package information data.

  5. Check that our package preferences work as intended: apt-cache policy chromium linux-base

    It should list chromium from Debian as a candidate, but linux-base should be from Ubuntu (even if Debian has newer version, as in example below):

    chromium:
      Installed: 78.0.3904.108-1~deb10u1
      Candidate: 78.0.3904.108-1~deb10u1
      Version table:
    *** 78.0.3904.108-1~deb10u1 999
            -10 http://deb.debian.org/debian-security stable/updates/main amd64 Packages
            100 /var/lib/dpkg/status
        78.0.3904.97-1~deb10u1 999
            -10 http://deb.debian.org/debian stable/main amd64 Packages
    linux-base:
      Installed: 4.5ubuntu2
      Candidate: 4.5ubuntu2
      Version table:
        4.6 -10
            -10 http://deb.debian.org/debian stable/main amd64 Packages
            -10 http://deb.debian.org/debian stable/main i386 Packages
    *** 4.5ubuntu2 500
            500 http://ru.archive.ubuntu.com/ubuntu eoan/main amd64 Packages
            500 http://ru.archive.ubuntu.com/ubuntu eoan/main i386 Packages
            100 /var/lib/dpkg/status
    

  6. Install Chromium: sudo apt install chromium