How to: Set Firefox Flatpak as default for x-www-browser

June 28, 2023 @ 11:52

Here is just a quick one, I want to share.

On my Debian desktop systems (and ubuntu ones before), I install firefox these days from flatpak. The reason for this is obvious, the freshness of the packages I get compared to the ones from debian, which ship always firefox’ ESR version (what would work for most, but I prefer an up-to-date browser:))

On XFCE and Gnome you can set the default applications, but that is sometimes not enough. Setting the default value for the x-www-browser link, is necessary so all X-applications use the correct browser for links.

With the update-alternatives command we can change those links. Let’s do this for the firefox flatpak example:

In short this command would do the trick

$ sudo update-alternatives --config x-www-browser
Es gibt 2 Auswahlmöglichkeiten für die Alternative x-www-browser (welche /usr/bin/x-www-browser bereitstellen).

  Auswahl      Pfad                                              Priorität Status
------------------------------------------------------------
* 0            /usr/bin/firefox-esr                               70        automatischer Modus
  1            /usr/bin/chromium                                  40        manueller Modus
  2            /usr/bin/firefox-esr                               70        manueller Modus

Drücken Sie die Eingabetaste, um die aktuelle Wahl[*] beizubehalten,
oder geben Sie die Auswahlnummer ein: 

You can see here, that you now can choose your new default for x-www-browser. But wait, we have already firefox installed as flatpak, but it is not showing off here:-O

By default the flatpak is not promoting firefox as new possible choice for the x-www-browser link, so we have to it. That’s pretty easy done with

sudo update-alternatives --install /usr/bin/x-www-browser x-www-browser /var/lib/flatpak/exports/bin/org.mozilla.firefox 42

To understand the command, we have a quick look into the man page

...
COMMANDS
       --install link name path priority [--slave link name path]...
Add a group of alternatives to the system.  link is the generic name for the master link, name is the name of its symlink in the alternatives directory, and path is the alternative being introduced for the master link. ....

So the first argument is the path to the link itself, the second one the name , the third the path to our executable we want as new default and the last is the priority.

Now we can hit the sudo update-alternative --config x-www-browser command again and whe should now be able to set our flatpak firefox installation as new default

$ sudo update-alternatives --config x-www-browser
Es gibt 3 Auswahlmöglichkeiten für die Alternative x-www-browser (welche /usr/bin/x-www-browser bereitstellen).

  Auswahl      Pfad                                              Priorität Status
------------------------------------------------------------
* 0            /usr/bin/firefox-esr                               70        automatischer Modus
  1            /usr/bin/chromium                                  40        manueller Modus
  2            /usr/bin/firefox-esr                               70        manueller Modus
  3            /var/lib/flatpak/exports/bin/org.mozilla.firefox   42        manueller Modus

Drücken Sie die Eingabetaste, um die aktuelle Wahl[*] beizubehalten,
oder geben Sie die Auswahlnummer ein: 3
update-alternatives: /var/lib/flatpak/exports/bin/org.mozilla.firefox wird verwendet, um /usr/bin/x-www-browser (x-www-browser) im manuellen Modus bereitzustellen

And we are done!:blush: