How to set browser environment variable on Linux

The purpose of this tutorial is to show how to set the web browser environment variable on Linux. Setting environment variables is usually how users can set the default applications and programs used on their Linux system. Therefore, the browser environment variable should point to the user’s desired default web browser.

In the case of a default web browser, this setting is best configured by the GUI itself. Simply setting the $BROWSER variable is not going to give you the the result you are expecting. Manually setting the web browser environment variable through other means is possible, but the process for doing so will vary across distributions and desktop environments.

In this tutorial, you will see how to set the web browser environment variable (set default web browser) from GUI or command line.

In this tutorial you will learn:

  • How to set browser environment variable
  • How to set default web browser from GUI
  • How to set default web browser with update-alternatives command
How to set browser environment variable on Linux
How to set browser environment variable on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to set default web browser via GUI



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!


As mentioned, the best method you will find is to let your GUI settings dictate the default web browser. All desktop environment’s will have a “default applications” panel where you can select the default web browser.

NOTE
In case you are using KDE Plasma for your desktop environment, see our tutorial on How to set KDE default web browser.
  1. First, search for the Default Applications settings in your desktop’s application launcher.
    Opening the Default Applications settings menu
    Opening the Default Applications settings menu
  2. Next, select your desired default web browser from the drop down menu.
    Selecting default web browser from GUI
    Selecting default web browser from GUI

How to set default web browser via command line

To set the default web browser from command line, execute the following command:

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




The menu to make your selection should look like this:

Setting default web browser from command line
Setting default web browser from command line

Enter the number that corresponds to your preferred web browser.

Desktop environments that rely on freedesktop.org as part of their base system, such as GNOME, KDE, and others, can use xdg commands to configure a default web browser, though the methods shown above are more recommended.

Show default web browser:

$ xdg-settings get default-web-browser

Set default web browser (Chromium in this example):

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

Closing Thoughts

In this tutorial, we saw how to set the default web browser on Linux. This can be done from GUI or command line. Setting a browser environment variable does not work the same as users might have come to expect. For this reason, it is better to use your desktop environment’s Default Applications menu to set the default web browser. Alternatively, the command line methods shown above will also work.




It is technically possible to set the default web browser via xdg commands or with a symbolic link from /usr/bin/x-www-browser. As a matter of fact, there are many methods to do this, and they all vary depending on the desktop environment and distro. These other methods can be used as a last resort.



Comments and Discussions
Linux Forum