In this article, we will delve into the process of setting the default browser in Ubuntu using the command line. This can be a handy skill to have, especially if you’re managing multiple systems or working in a server environment where a GUI isn’t available.
To set the default browser via the command line in Ubuntu, you can use the
update-alternatives command, the
xdg-settings command, or modify the
~/.config/mimeapps.list file. Each method allows you to easily choose your preferred browser as the default.
Understanding the Default Browser
The default browser is the web browser that will automatically open when you click on a web link or try to view HTML files. In Ubuntu, you can have several browsers installed, but only one can be the default.
One of the simplest ways to set the default browser in Ubuntu is using the
update-alternatives command. This command is used to maintain symbolic links determining default commands.
Step 1: Open the terminal and type the following command:
sudo update-alternatives --config x-www-browser
This command will display a list of installed web browsers, each with a corresponding number.
Step 2: To set your default browser, simply type the number corresponding to your preferred browser and press Enter.
Alternatively, you can set the default browser for all programs using the
sensible-browser command by exporting the
BROWSER variable. To do this, add the line
export BROWSER=/usr/bin/firefox to your
~/.bashrc file, replacing
/usr/bin/firefox with the path to your desired browser.
xdg-settings command is part of the xdg-utils package, which provides tools for managing desktop environment settings.
Step 1: To check the current default browser, type the following command:
xdg-settings get default-web-browser
Step 2: To set a new default browser, use the following command:
xdg-settings set default-web-browser <browser.desktop>
<browser.desktop> with the desktop file of your desired browser (e.g.,
Another way to set the default browser is by modifying the
Step 1: Open the
~/.config/mimeapps.list file in a text editor.
Step 2: Look for the line starting with
x-scheme-handler/http= and modify it to point to the desktop file of your desired browser.
Step 3: Save the file.
Using GUI Tools
If you prefer using a GUI, you can use the
gnome-default-applications-properties command to open a window where you can choose your preferred browser as the default.
Other desktop environments may have their own tools for setting the default browser. For example, XFCE has a GUI setting in Settings -> Preferred Applications.
Setting the default browser in Ubuntu via the command line is a straightforward process that can be accomplished using various methods. Whether you prefer using
xdg-settings, or modifying the
mimeapps.list file, each method is effective and can be done quickly. Remember, some applications may have their own settings and may not respect the system-wide default browser. In those cases, you may need to configure the browser within the application itself.
To check the current default browser in Ubuntu, you can use the
xdg-settings get default-web-browser command in the terminal.
To set the default browser for all programs in Ubuntu, you can export the
BROWSER variable in the
~/.bashrc file by adding the line
export BROWSER=/usr/bin/firefox (replace
/usr/bin/firefox with the path to your desired browser).
Yes, you can set different default browsers for different file types in Ubuntu by modifying the
~/.config/mimeapps.list file. Each file type has a corresponding entry in this file, and you can specify the desired browser for each file type.
If the desired browser is not listed in the
update-alternatives command, it means that the browser is not registered as an alternative. You can manually add the browser as an alternative using the
sudo update-alternatives --install /usr/bin/x-www-browser x-www-browser /path/to/browser 100 command, replacing
/path/to/browser with the actual path to the browser executable.
Setting the default browser using the command line will only affect the system-wide default browser. Some applications may have their own settings for the default browser, and they may not respect the system-wide setting. In those cases, you may need to configure the browser within the application itself.