42

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?

49

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
| improve this answer | |
  • 2
    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 :( – Arpad Horvath Apr 10 '12 at 8:51
  • Is there command line for to set document viewer as default for PDF. – Rahul Raj Mar 2 '16 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 '18 at 18:00
21

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
| improve this answer | |
  • XFCE seems to set this with it's GUI Settings -> Preferred applications – Xen2050 Dec 22 '17 at 21:40
  • 1
    This helped me set the default browser for jupyter notebook. – jchook Jan 29 '18 at 1:02
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.

| improve this answer | |
1

Try the following commands:

sudo update-alternatives --config x-www-browser
sudo update-alternatives --config www-browser
| improve this answer | |
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
| improve this answer | |
0

Set Chrome as Default Browser from Command Line

open -a "Google Chrome" --args --make-default-browser

Read complete article here: http://www.blogcookie.com/2016/07/set-chrome-default-browser-command-line/

| improve this answer | |
  • What exactly does this do/change? – Xen2050 Dec 22 '17 at 21:41
0

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
| improve this answer | |
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

| improve this answer | |
  • Looks like this is the file that xdg-settings set default-web-browser google-chrome.desktop updates. – eichin Apr 16 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. – Martin Dorey Apr 17 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.