There are many questions similar to mine (e.g. xdg-open not open default browser or xdgutils - xdg-settings not setting default-web-browser in gentoo, but none of the answers helped in my case. Therefor I ask for my particular situation:
On Centos 7 I have no free desktop manager running, I just run some X11 applications (like VS Code) from the command line where the DISPLAY variable is set to the X server on the (Windows) machine I connect from.
On the Centos machine I have two browsers installed, firefox and google-chrome. I can start both browsers just by typing firefox resp. google-chrome in the bash terminal.
xdg-open is available and it opens links in google-chrome - as does VS Code. However I want to change this to firefox.
I tried:
Ticking "Default browser" in Firefox's GUI preferences.
Using
xdg-settings, butxdg-settings get default-web-browserreturns "xdg-settings: unknown desktop environment"
Setting $BROWSER. In bash I issued
export BROWSER=firefoxbut still
google-chromeis started byxdg-open
How can I set in this environment the default browser to firefox?
Note: Strangely on another machine with Centos 6 (and "no desktop environment" either) the export BROWSER method works!
The desired behavior can be set in the
mimeapps.listconfiguration files described in the XDG MIME Applications specification.TLDR: In order to configure firefox as the default browser for your user create
~/.config/mimeapps.listcontaining the following lines:Details:
xdg-utilslikexdg-open(1)andxdg-mime(1)look for this file in the locations listed under the File name and location section of this specification:$XDG_CONFIG_HOME/$desktop-mimeapps.listuser overrides, desktop-specific (for advanced users)$XDG_CONFIG_HOME/mimeapps.listuser overrides (recommended location for user configuration GUIs)$XDG_CONFIG_DIRS/$desktop-mimeapps.listsysadmin and ISV overrides, desktop-specific$XDG_CONFIG_DIRS/mimeapps.listsysadmin and ISV overrides$XDG_DATA_HOME/applications/$desktop-mimeapps.listfor completeness, deprecated, desktop-specific$XDG_DATA_HOME/applications/mimeapps.listfor compatibility, deprecated$XDG_DATA_DIRS/applications/$desktop-mimeapps.listdistribution-provided defaults, desktop-specific$XDG_DATA_DIRS/applications/mimeapps.listdistribution-provided defaultsThe locations for the
$XDGvariables are governed by the XDG Base Directory specification. If you want to figure out wherexdg-utilsare looking for configuration in your particular case, run them with theXDG_UTILS_DEBUG_LEVELenvironment variable like so: