64

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?

sdu
  • 1,640

11 Answers11

72

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
Jorge Castro
  • 73,717
karthick87
  • 84,513
37

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
stilllife
  • 537
5

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
Frank N
  • 1,430
5

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

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

muru
  • 207,228
RayLuo
  • 151
2

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
azzamsa
  • 209
1

first of all, I use Ubuntu 22.04 and wanted to set Midori as my default browser, but this was even not listed in the list of browsers.

Reading a bit discovered that the configuration file to define default browser was:

~/.config/mimeapps.list

Then as I have several browsers I discovered that In order to add to the list of browsers I needed to find which was the *.desktop Application Meta Description of Midori, those files *.desktop are located in several places of ubuntu but mainly on:

/usr/share/applications

With this information and after comparing what changes in the file after setting default browser in ubuntu/settings the following images show how I finally set midori as default browser:

  1. Find the name *.desktop of midori, in my case was midori-ng.desktop
  2. Edit the file ~/.config/mimeapps.list
  3. Add entries of midori-ng.desktop in the list of available brosers.
  4. In my case midori-ng.desktop was but defined, because didn't pass the parameter or arguments to the app so I couldn't for example open a link that was in a pdf. So I had to edit the midori-ng.desktop file to set the parameter as midori %u.

where to put midori to be in the combobox of default browsers Added Midori in the combobox of default browsers. added midori as default browser Added Midori as default browser Edit midori-ng.dekstop Edit midori-ng.dekstop Edit midori-ng.dekstop Added missing handler of argument or parameter %u Midori Now Appears Listed in Settings Midori Now Appears Listed In Settings

efsandino
  • 163
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

Martin Dorey
  • 227
  • 2
  • 8
0

Try the following commands:

sudo update-alternatives --config x-www-browser
sudo update-alternatives --config www-browser
ddeimeke
  • 3,149
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
Wernight
  • 1,413
-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.

Luc
  • 1,263