63

Tried to set the default browser using the GUI tools but this didn't work overall. Is there a way to configure the system wide default browser from command line?

10 Answers 10

71

Execute the following command in terminal,to change the default browser.

sudo update-alternatives --config x-www-browser

Sample output:

karthick@Ubuntu-desktop:~$ sudo update-alternatives --config x-www-browser 
There are 3 choices for the alternative x-www-browser (providing /usr/bin/x-www-browser).

  Selection    Path                    Priority   Status
------------------------------------------------------------
  0            /usr/bin/google-chrome   200       auto mode
* 1            /usr/bin/firefox         40        manual mode
  2            /usr/bin/google-chrome   200       manual mode
  3            /usr/bin/opera           90        manual mode
  • Press enter to keep the default[*].

  • Right now I have firefox as my default web browser.

  • If i want google-chrome as default browser then I will type 3 and hit enter.

Note:

  • If you want to configure a commandline browser,then you have to configure

    sudo update-alternatives --config www-browser

  • Alternate way is to add the following line export BROWSER=/usr/bin/firefox to your ~/.bashrc

  • Add the above line in the last,

    enter code here

Alternative GUI Method:

  • You can also set the default browser in Gnome applications,type the following in terminal and press Enter gnome-default-applications-properties
  • It will Open a Window.Now you can choose your preferred browser to set it default. alt text
3
  • 3
    My gnome-www-browser is a link to epiphany, my x-www-browser is a link to chromium, but the right click in the terminal (gnome-terminal and terminator) opens the url with firefox :( Apr 10, 2012 at 8:51
  • Is there command line for to set document viewer as default for PDF.
    – Rahul Raj
    Mar 2, 2016 at 17:26
  • 1
    This doesn't work for Ubuntu 18.04. The answer from stilllife works: xdg-settings set default-web-browser chromium-browser.desktop
    – Graham
    Jul 29, 2018 at 18:00
31

The already suggested methods might not work for some app (e.g. HipChat).

I've had to do:

xdg-settings set default-web-browser chromium-browser.desktop
3
  • XFCE seems to set this with it's GUI Settings -> Preferred applications
    – Xen2050
    Dec 22, 2017 at 21:40
  • 1
    This helped me set the default browser for jupyter notebook.
    – jchook
    Jan 29, 2018 at 1:02
  • Worked for me in Debian 10. I've downloaded Firefox 85, untargziped into /lib/firefox, created .desktop file into /usr/share/applications/ but it is not appearing into Default Browsers choices in GNOME settings. This above command works well in this case. Jan 27, 2021 at 1:45
4

It depends a bit on what "default browser" exactly means, i.e. for what purpose you want to change the browser. Some programs ignore any system-wide settings and use their own settings.

That said, you can set the default browser for all programs starting the browser with the generic sensible-browser command by exporting the BROWSER variable, e.g. add a line to the file ~/.bashrc:

export BROWSER=/usr/bin/firefox

The other generic way of calling a browser is x-www-browser, this one is handled by the Debian "alternatives" system:

sudo update-alternatives --config x-www-browser

If you want to configure a commandline-only browser like lynx, you have to configure www-browser instead.

4

Googlers, to do this fully scripted (no interaction whatsoever) in a setup script:

sudo update-alternatives --install /usr/bin/x-www-browser x-www-browser /usr/bin/google-chrome 500
sudo update-alternatives --set x-www-browser /usr/bin/google-chrome

…and similary for your favorite editor:

sudo update-alternatives --install /usr/bin/editor editor /usr/bin/pluma 500
sudo update-alternatives --set editor /usr/bin/pluma
3
  • what does 500 stand for?
    – cipricus
    Jan 10, 2022 at 8:09
  • 1
    it's just a “sufficently high“ (but mostly guessed) priority value to “win” over all existing.
    – Frank N
    Jan 12, 2022 at 17:58
  • Didn't work for me when I tried /home/myusernam/.helper_scripts/browser_wrapper where the wrapper just does: vivaldi-stable --new-window --force-device-scale-factor=2 $@ 2>/dev/null, I get a message: [49696:49722:0226/123433.848972:ERROR:bus.cc(398)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix"). So nice to have these GUI that just ignore BROWSER Feb 26, 2023 at 21:33
2

The top two answers here both look promising, yet only one of them worked for me. Have you ever wondered why? For the sake of completeness, this is an official wiki page from Debian:

Foreign applications

Default for foreign programs (system-wide)

Programs which are not designed for the user's desktop environment do not obey the browser settings of the desktop environment (GNOME or KDE). For example, Thunderbird ignores desktop environment-specific browser settings. The default browser for generic applications can be changed for the whole system by reconfiguring the x-www-browser alternative.

# update-alternatives --config x-www-browser

Default for foreign programs (user-specific)

Some applications use xdg-open (part of xdg-utils). xdg-settings can be used to both get and change the default browser. Local settings can also be found in the users' home in ~/.config/mimeapps.list.

$ xdg-settings get default-web-browser
chromium.desktop

$ xdg-settings set default-web-browser firefox-esr.desktop
1

sudo update-alternatives --config x-www-browser

only shows installed application trough apt-get, for manual installation you can use

sudo update-alternatives --install /usr/bin/x-www-browser x-www-browser /opt/yourapp/yourapp 200
sudo update-alternatives --set x-www-browser /opt/yourapp/yourapp
0

Try the following commands:

sudo update-alternatives --config x-www-browser
sudo update-alternatives --config www-browser
0

Additional to those answer google-chrome has usually a symbolic link to the channel-specific version:

/usr/bin/google-chrome -> /etc/alternatives/google-chrome -> /usr/bin/google-chrome-beta
0

For me, today, running Gnome 3, ~/.config/mimeapps.list is what controls gnome-open <url> and Java's Desktop.getDesktop().browse(new URI(url)). This is what changes there when I run gnome-control-center (the "Details" applet in the settings application from the top right menu) and change Default Applications, Web from Google Chrome to Firefox ESR:

11c11
< x-scheme-handler/http=google-chrome.desktop
---
> x-scheme-handler/http=firefox-esr.desktop`

As hoped, I could revert that from the command line with:

perl -i -wpe 's@x-scheme-handler/http(s?)=firefox-esr.desktop@x-scheme-handler/http$1=google-chrome.desktop@' ~/.config/mimeapps.list

... and put it back with:

perl -i -wpe 's@x-scheme-handler/http(s?)=google-chrome.desktop@x-scheme-handler/http$1=firefox-esr.desktop@' ~/.config/mimeapps.list

2
  • Looks like this is the file that xdg-settings set default-web-browser google-chrome.desktop updates.
    – eichin
    Apr 16, 2020 at 6:38
  • For me that seems to be replacing .local/share/applications/mimeapps.list... with the same content it already has. Something's broken but perhaps it's just for me. Apr 17, 2020 at 8:34
-1

For me, sensible-browser seems to just call /usr/bin/gnome-www-browser, which symlinks to /etc/alternatives/gnome-www-browser, which symlinks to the browser. To change it, I needed to do this:

sudo rm /etc/alternatives/gnome-www-browser
sudo ln -s ~/bin/firefox /etc/alternatives/gnome-www-browser

You should put the full path to the browser that you want to use in place of ~/bin/firefox.

Now, when I run sensible-browser https://example.com, Firefox opens as expected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .