Linux Commands

How to open default browser from command line Linux

On Ubuntu, you might have several web browsers installed, which are utilized according to your browsing preferences. Although, we all have a most favorite web browser to use 90% of the internet every day. In Linux, it is preferred to state the best browser as the default browser. This default browser will also allow you to open links from the terminal.

Checking default web browser:

To set, change or view the default browser through a terminal or user interface is simple yet straightforward.
Write out the below-given command to know the default browser of your Linux system.

$ xdg-settings get default-web-browser

You can look into the list of other default applications, including your default browser. For performing this, there are two methods, In the first method, you can use the below-given command, and it will redirect you to the Default Application windows.

$ gnome-control-center default-applications

Searching “Default Applications” in the activities is considered as the second method.

The highlighted web browser in the “Web” option is already picked as the default web browser.

You can also check out the list of other available alternatives for browsing the web on your system.

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

The output declares that “Google Chrome” also exists as a web browser on our Ubuntu.

Opening default web browser from the command line:

Now, we will try to open the google instance in the default web browser, which is “firefox” in our case. Utilize the below-given command in your terminal if you want to do so.

$ xdg-open https://www.google.co.uk

Here, you can see terminal command execution successfully open a google instance in our default web browser.

Changing default web browser:

For setting any other browser as the default one, you have to execute the “xdg” settings command with the browser name at the end. We will set “Google Chrome” as the default browser on our Linux system in the following example.

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

Again, open any web instance by specifying its URL in the “xdg” open command. Furthermore, we have chosen “Google” for the testing.

$ xdg-open https://www.google.co.uk

The output states that we are successful in setting “Google Chrome” as your default browser.

Conclusion:

As Linux users, we all have various installed web browsers, which we use according to our web preferences. Still, there exists a possibility of 90% using a single web browser for browsing activities which turns to be our default web browser. In this article, we have seen opening the default browser for any web instance from the command line. Furthermore, the procedure of viewing and setting any other alternatives to your default browser is also provided.

About the author

Talha Saif Malik

Talha is a contributor at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.