1. Overview

When we work with the Linux command line – for example, in a terminal – sometimes we want to open a website URL in the default browser.

Usually, we need to copy the URL string, then open the browser. Finally, we move to the address bar, paste the address, and press enter.

In this tutorial, we’ll introduce a much easier way to open a URL in the default browser.

2. The gnome-open and kde-open Commands

GNOME and KDE are two popular desktop environments, and many Linux distributions use one of them as the default desktop environment.

GNOME ships with a tool called gnome-open. It opens the specified item with the preferred GNOME application for that file/MIME type.

Therefore, if we pass a URL string to the gnome-open command, for example:

gnome-open https://www.baeldung.com/linux

It will open the URL in the default browser:


If we use KDE as our desktop environment, the kde-open command works in the same way.

However, what if we don’t use GNOME or KDE as our desktop environment? Is there a command that will work crossing desktop environments?

Next, we’ll introduce three approaches that work independently of the desktop environment we’re using.

3. The xdg-open Command

The xdg-open command can open a file or URL in the user’s preferred application. It’s a member of the xdg-utils package. Many distributions have installed this package by default.

The usage is pretty similar to the gnome-open or kde-open command — xdg-open URL:


4. The gio open Command

Glib is a core-level library in a Linux system. If our Glib version is later than 2.49.3, the gio command is available.

We can execute gio open URL to open the given URL in the default browser:


5. Using Python’s webbrowser Module

Today, Python is pre-installed in most modern Linux distributions. Python ships a built-in webbrowser module so that we can easily control the browser in Python.

To open a URL in the browser, we just pass the URL to the python command:

python -m webbrowser URL

Next, let’s give it a try:


6. Conclusion

In this quick article, we’ve discussed several ways to open a URL in the default browser from the Linux command line.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.