WSL (Ubuntu): how to open localhost in browser from bash terminal WSL (Ubuntu): how to open localhost in browser from bash terminal windows windows

WSL (Ubuntu): how to open localhost in browser from bash terminal


You are almost there. Just add an alias for the windows chrome executablehttp://www.linfo.org/alias.html

alias chrome="/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe"

Now you can simply run chrome localhost and open chrome in any web location you desire.


You can invoke the Windows command line from Bash and use Windows file association to open URL with the default Windows browser.

To do so just type in Bash:

cmd.exe /C start http://localhost

In my case this loads localhost in Chrome, note that the full URL is necessary for Windows to decide what to do.

This is similar to what open does in MacOS, hence you may find useful to directly alias the command and use it also for other type of files:

# add this to .bash_aliasesopen='cmd.exe /C start'

Now you can open URL or open file.pdf directly from WSL.


Note: since you are simply redirecting commands to cmd.exe, it needs to have access to the file your working with. As a consequence the above solution will work when you find yourself in the Windows file system, but probably will fail when you are working with files in Linux partition (i.e. in the tmp or in the bin folder). This probably has been fixed in the new version of the WSL but I have not tested it.


To open localhost in browser from bash terminal, you need to configure wsl so that it
defaults to whatever browser has been set as default in your windows 10 system.

You can do this by using some tools from wslu ("A collection of utilities for WSL").
For this purpose you need.

  • wslview (-u, --unregister "remove wslview as the default WSL web browser.
    -r, --register "register wslview as the default WSL web browser.)

  • wslpath (-a "force result to absolute path format",
    -u "translate from a Windows path to a WSL path (default)")

You need to register your preferred browsers like this...
For Google Chrome:
wslview -r $(wslpath -au 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe')

For Microsoft Edge:
wslview -r $(wslpath -au 'C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe')

Now you can open localhost as x-www-browser localhost:8080 or www-browser localhost:8080 and x-www-browser or www-browser will default to whatever is your current windows 10 default browser provided it has been registered as described above.
Do not forget to indicate the port; localhost alone did not work for me.

To unregister any browser just change the -r flag to -u.

Have a look at wslview help: info wslview <enter> in the wsl terminaland wslpath <enter> for help with wslpath.