How to set the Default Browser from the Command Line?

74,593

Solution 1

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

Solution 2

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

Solution 3

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.

Solution 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

Solution 5

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
Share:
74,593

Related videos on Youtube

sdu
Author by

sdu

Updated on September 17, 2022

Comments

  • sdu
    sdu almost 2 years

    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?

  • Arpad Horvath
    Arpad Horvath about 12 years
    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 :(
  • Rahul Raj
    Rahul Raj over 8 years
    Is there command line for to set document viewer as default for PDF.
  • Xen2050
    Xen2050 over 6 years
    XFCE seems to set this with it's GUI Settings -> Preferred applications
  • jchook
    jchook over 6 years
    This helped me set the default browser for jupyter notebook.
  • Graham
    Graham almost 6 years
    This doesn't work for Ubuntu 18.04. The answer from stilllife works: xdg-settings set default-web-browser chromium-browser.desktop
  • eichin
    eichin about 4 years
    Looks like this is the file that xdg-settings set default-web-browser google-chrome.desktop updates.
  • Martin Dorey
    Martin Dorey about 4 years
    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.
  • Enrique René
    Enrique René over 3 years
    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.
  • cipricus
    cipricus over 2 years
    what does 500 stand for?
  • Frank Nocke
    Frank Nocke over 2 years
    it's just a “sufficently high“ (but mostly guessed) priority value to “win” over all existing.