How to launch default web browser from the terminal?

348,635

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
Share:
348,635

Related videos on Youtube

Luca
Author by

Luca

Updated on September 17, 2022

Comments

  • Luca
    Luca almost 2 years

    I was wondering what's the terminal command to open the default web browser.

  • marenostrum
    marenostrum over 13 years
    With default Ubuntu setup, sensible-browser and xdg-open commands work as well.
  • enzotib
    enzotib over 13 years
    What about the differences between sensible-utils package and the system of alternatives found in /etc/alternatives and modified by update-alternatives?
  • yop83
    yop83 over 13 years
    The 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 like sensible-browser
  • Piskvor left the building
    Piskvor left the building almost 13 years
    @Stefan Lasiewski: xdg-open should do the same thing - actually, it will call gnome-open, or kde-open, or whatever, depending on your desktop environment. Thus it's more portable.
  • incrop
    incrop about 10 years
    For me sensible-browser opens Opera instead pf default Chrome. xdg-open works as expected.
  • Thupten
    Thupten almost 10 years
    what does xdg stand for? Its hard to remember without knowing that.
  • Luca
    Luca almost 10 years
    XDG stands for X Desktop Group aka freedesktop.org
  • Andreas Hacker
    Andreas Hacker over 7 years
    in Ubuntu 16.04, gnome-open is not installed by default
  • Andreas Hacker
    Andreas Hacker over 7 years
    for 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
    Andreas Hacker over 7 years
    what @Incrop said is still true for Ubuntu 16.04, this opens Firefox instead of my default browser Chromium.
  • Andreas Hacker
    Andreas Hacker over 7 years
    Still still works on a default Ubuntu 16.04 installation.
  • phil294
    phil294 almost 7 years
    if 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
    flurbius over 6 years
    This 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
    flurbius over 6 years
    gnome-open is dependent on gnome desktop, better off using xdg as its more common
  • Tankman六四
    Tankman六四 over 6 years
    sensible-browser doesn't follow user preference configured in unity-control-centre. xdg-open does.
  • AlwaysTalkingAboutMyDog
    AlwaysTalkingAboutMyDog about 5 years
    Consider 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
    Mohamed Allal about 5 years
    @Zzzach...done! and i get the point. Though it was a simple matter.
  • Mike
    Mike almost 5 years
    Looks like xdg-open is deprecated. Use gio open <filename>, instead.
  • NeoShow
    NeoShow over 4 years
    Although my default (gnome) browser is Firefox, sensible-browser opens Chrome.
  • NeoShow
    NeoShow over 4 years
    gnome-open is not installed by default lately.
  • pyrsmk
    pyrsmk about 4 years
    For me, under Linux Mint, sensible-browser opens the right one, and xdg-open opens the wrong one.
  • ram0nvaldez
    ram0nvaldez over 3 years
    this one opens chrome despite another browser is the default
  • ram0nvaldez
    ram0nvaldez over 3 years
    this one is nice
  • Vik
    Vik over 3 years
    @Mike it isn't deprecated. reddit.com/r/archlinux/comments/8mniks/…