xdg-open not open default browser

mike picture mike · Dec 15, 2016 · Viewed 35.4k times · Source

I have the following scenario: Ubuntu 16.04 machine with firefox and chrome installed, chrome being my default browser.

I check this actions in the shell :

cat /usr/share/applications/defaults.list
cat /etc/mailcap
cat /.config/mimeapps.list
cat /.local/share/applications/mimeinfo.cache

x-www-browser-> chrome is launch
xdg-mime query default text/html
response:
google-chrome.desktop

And does not appear firefox by any side, always chrome. This is fine. Also check:

Click on a desktop file file.html -> chrome is launch

And now comes the strange, if I run:

xdg-open "http://www.example.com"

For some strange reason it always opens firefox. I do not know why, could anyone help me?

Answer

Nolan Akash picture Nolan Akash · Jun 17, 2018

To set a default browser, make sure that a .desktop file exists for your preferred browser. I'll be setting Mozilla Iceweasel for this example:

$ ls /usr/share/applications/iceweasel.desktop
iceweasel.desktop

Assured you have the file, run:

$ xdg-settings set default-web-browser iceweasel.desktop
# Test that it works
$ xdg-open "http://example.com"

If you don't have a .desktop file:

I use the program surf, which doesn't have a .desktop file. To set this as your web browser, first create the file ~/.local/share/applications/surf.desktop with this following content:

[Desktop Entry]
Type=Application
Name=surf
Comment=Surf minimal web browser
Terminal=false
Exec=surf
Categories=Network;WebBrowser

While not all of this content is required, it helps categorize the file for any future use.

Set the default browser like normal:

$ xdg-settings set default-web-browser surf.desktop

And now you're good to go!