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
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to set default web browser via GUI
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.
In case you are using KDE Plasma for your desktop environment, see our tutorial on How to set KDE default web browser.
- First, search for the Default Applications settings in your desktop’s application launcher.
- Next, select your desired default web browser from the drop down menu.
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:
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
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
xdgcommands 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.