The Looseleaf Papers

Coralling Chrome on Debian 9 (stretch)

Created

Modified

Published

For obnoxious reasons, I need to install Google Chrome on Linux instead of just using chromium.

$ echo 'deb http://dl.google.com/linux/chrome/deb/ stable main' | sudo tee /etc/apt/sources.list.d/tmp.list
$ sudo apt update && sudo apt install google-chrome-stable
<snip>
update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/gnome-www-browser (gnome-www-browser) in auto mode
<snip>

Dangit, chrome, I do not want you to be the default browser!

$ update-alternatives --display gnome-www-browser
gnome-www-browser - auto mode
  link best version is /usr/bin/google-chrome-stable
  link currently points to /usr/bin/google-chrome-stable
  link gnome-www-browser is /usr/bin/gnome-www-browser
  slave gnome-www-browser.1.gz is /usr/share/man/man1/gnome-www-browser.1.gz
/usr/bin/chromium - priority 40
/usr/bin/firefox-esr - priority 70
  slave gnome-www-browser.1.gz: /usr/share/man/man1/firefox-esr.1.gz
/usr/bin/google-chrome-stable - priority 200
/usr/bin/iceweasel - priority 70
  slave gnome-www-browser.1.gz: /usr/share/man/man1/iceweasel.1.gz

In auto mode, highest priority wins, and 200 beats 70.

Let’s fix it. [1]

$ sudo update-alternatives --config gnome-www-browser
There are 4 choices for the alternative gnome-www-browser (providing /usr/bin/gnome-www-browser).

  Selection    Path                           Priority   Status
------------------------------------------------------------
* 0            /usr/bin/google-chrome-stable   200       auto mode
  1            /usr/bin/chromium               40        manual mode
  2            /usr/bin/firefox-esr            70        manual mode
  3            /usr/bin/google-chrome-stable   200       manual mode
  4            /usr/bin/iceweasel              70        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/firefox-esr to provide /usr/bin/gnome-www-browser (gnome-www-browser) in manual mode

Let’s check our work.

$ update-alternatives --display gnome-www-browser
gnome-www-browser - manual mode
  link best version is /usr/bin/google-chrome-stable
  link currently points to /usr/bin/firefox-esr
  link gnome-www-browser is /usr/bin/gnome-www-browser
  slave gnome-www-browser.1.gz is /usr/share/man/man1/gnome-www-browser.1.gz
/usr/bin/chromium - priority 40
/usr/bin/firefox-esr - priority 70
  slave gnome-www-browser.1.gz: /usr/share/man/man1/firefox-esr.1.gz
/usr/bin/google-chrome-stable - priority 200
/usr/bin/iceweasel - priority 70
  slave gnome-www-browser.1.gz: /usr/share/man/man1/iceweasel.1.gz

Alright, is chrome assigned to anything else?

$ update-alternatives --get-selections | grep chrome
google-chrome                  auto     /usr/bin/google-chrome-stable

That’s fine.

But it turns out life is more complicated, because update-alternatives is only half the battle.

$ grep chrome /usr/share/applications/defaults.list
text/html=google-chrome.desktop;
text/xml=google-chrome.desktop;
application/xhtml_xml=google-chrome.desktop;
image/webp=google-chrome.desktop;
x-scheme-handler/http=google-chrome.desktop;
x-scheme-handler/https=google-chrome.desktop;
x-scheme-handler/ftp=google-chrome.desktop;

Where does chrome do this? In the postinst script:

# Updates defaults.list file if present.
update_defaults_list() {
  # $1: name of the .desktop file

  local DEFAULTS_FILE="/usr/share/applications/defaults.list"

  if [ ! -f "${DEFAULTS_FILE}" ]; then
    return
  fi

  # Split key-value pair out of MimeType= line from the .desktop file,
  # then split semicolon-separated list of mime types (they should not contain
  # spaces).
  mime_types="$(grep MimeType= /usr/share/applications/${1} |
                cut -d '=' -f 2- |
                tr ';' ' ')"
  for mime_type in ${mime_types}; do
    if egrep -q "^${mime_type}=" "${DEFAULTS_FILE}"; then
      if ! egrep -q "^${mime_type}=.*${1}" "${DEFAULTS_FILE}"; then
        default_apps="$(grep ${mime_type}= "${DEFAULTS_FILE}" |
                        cut -d '=' -f 2-)"
        egrep -v "^${mime_type}=" "${DEFAULTS_FILE}" > "${DEFAULTS_FILE}.new"
        echo "${mime_type}=${default_apps};${1}" >> "${DEFAULTS_FILE}.new"
        mv "${DEFAULTS_FILE}.new" "${DEFAULTS_FILE}"
      fi
    else
      # If there's no mention of the mime type in the file, add it.
      echo "${mime_type}=${1};" >> "${DEFAULTS_FILE}"
    fi
  done
}

update_defaults_list "google-chrome.desktop"

And what mimetypes does Chrome list in its desktop file?

$ grep MimeType /usr/share/applications/google-chrome.desktop
MimeType=text/html;text/xml;application/xhtml_xml;image/webp;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;

That’s a little presumptuous, I would say.

I would prefer that Google Chrome let me install it without root, but without apt I’m not sure it would update properly.

I’ve successfully extracted the Fedora/OpenSUSE RPM into my home directory and ran chrome from there. You simply need to make sure that the symlinks for the libraries are all there. This assumes that the libraries area already installed, and $HOME/bin is in my $PATH.

—jsbillings, March 9, 2011

https://unix.stackexchange.com/questions/8926/installing-chrome-on-linux-without-needing-to-be-root

[1]There are workarounds if you don’t have root privileges.