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 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:
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 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
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:
In this quick article, we’ve discussed several ways to open a URL in the default browser from the Linux command line.