How to launch default web browser from the terminal?
Solution 1
sensible-browser
is the command you're looking for.
Or:
xdg-open <URL>
.
Solution 2
Searching on Google I found the answer.
xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.
xdg-open is part of xdg-utils package and it's already installed on Ubuntu 10.10.
Solution 3
You can also use:
x-www-browser http://some-url.org
And it will open the URL in the default browser.
Solution 4
Just that you may find it useful. A fallback approach, and one liner.
URL="https://www.url.com/some"; xdg-open $URL || sensible-browser $URL || x-www-browser $URL || gnome-open $URL
Good reading for the no familiar with the logical operators https://www.howtogeek.com/269509/how-to-run-two-or-more-terminal-commands-at-once-in-linux/.
; => run in all cases,
|| => run if the precedent command failed (or)
&& => run only if the precedent command succeed
and
var=someval -> set a variable
$var -> invoke the variable
Solution 5
With default Ubuntu setup only gnome-open command comes to mind.
gnome-open http://askubuntu.com
Related videos on Youtube
Luca
Updated on September 17, 2022Comments
-
Luca almost 2 years
I was wondering what's the terminal command to open the default web browser.
-
marenostrum over 13 yearsWith default Ubuntu setup, sensible-browser and xdg-open commands work as well.
-
enzotib over 13 yearsWhat about the differences between
sensible-utils
package and the system of alternatives found in/etc/alternatives
and modified byupdate-alternatives
? -
yop83 over 13 yearsThe advantage is that you can use
gnome-open
for almost all file-types, URIs and directories. It's one command to learn, instead of trying to remember about obscure commands likesensible-browser
-
Piskvor left the building almost 13 years@Stefan Lasiewski:
xdg-open
should do the same thing - actually, it will callgnome-open
, orkde-open
, or whatever, depending on your desktop environment. Thus it's more portable. -
incrop about 10 yearsFor me
sensible-browser
opens Opera instead pf default Chrome.xdg-open
works as expected. -
Thupten almost 10 yearswhat does xdg stand for? Its hard to remember without knowing that.
-
Luca almost 10 yearsXDG stands for X Desktop Group aka freedesktop.org
-
Andreas Hacker over 7 yearsin Ubuntu 16.04, gnome-open is not installed by default
-
Andreas Hacker over 7 yearsfor me, in Ubuntu 16.04, this will open Firefox even though Chromium is set as the default browser in the "Default Applications" setting.
-
Andreas Hacker over 7 yearswhat @Incrop said is still true for Ubuntu 16.04, this opens Firefox instead of my default browser Chromium.
-
Andreas Hacker over 7 yearsStill still works on a default Ubuntu 16.04 installation.
-
phil294 almost 7 yearsif the user once configured to open html files with a text editor by default, this will not work. OP asks for a way to open the web browser, not the default application for html files (even though by default it's the same)
-
flurbius over 6 yearsThis will work on any gnu/linux distro that has x-server window manager (that is just about all of them - eg debian, *buntu, fedora, manjaro, Arch etc)
-
flurbius over 6 yearsgnome-open is dependent on gnome desktop, better off using xdg as its more common
-
Tankman六四 over 6 years
sensible-browser
doesn't follow user preference configured in unity-control-centre.xdg-open
does. -
AlwaysTalkingAboutMyDog about 5 yearsConsider explaining what this command does so that others that see this know more about your answer. Links are good, but you need to ensure the key content of the link is in your answer if it is part of your answer (incase the link dies in the future).
-
Mohamed Allal about 5 years@Zzzach...done! and i get the point. Though it was a simple matter.
-
Mike almost 5 yearsLooks like xdg-open is deprecated. Use gio open <filename>, instead.
-
NeoShow over 4 yearsAlthough my default (gnome) browser is Firefox,
sensible-browser
opens Chrome. -
NeoShow over 4 years
gnome-open
is not installed by default lately. -
pyrsmk about 4 yearsFor me, under Linux Mint, sensible-browser opens the right one, and xdg-open opens the wrong one.
-
ram0nvaldez over 3 yearsthis one opens chrome despite another browser is the default
-
ram0nvaldez over 3 yearsthis one is nice
-
Vik over 3 years@Mike it isn't deprecated. reddit.com/r/archlinux/comments/8mniks/…