WSL can open your default browser, but you need to tell it which browser to use

Windows Subsystem for Linux (WSL) runs a Linux environment inside Windows, but it doesn't automatically know how to reach your browser. When a program inside WSL tries to open a link, it has no direct path to Windows applications. You can fix this by setting an environment variable that tells WSL which browser command to run, or by using a helper script that bridges WSL and Windows.

The simplest approach depends on your setup. If you're running WSL 2 with a recent Windows build, you can use the wslview command or set the BROWSER environment variable to point to a Windows executable. For older setups or more control, you can write a small script that calls Windows browsers from inside WSL.

Key Takeaways

  • WSL cannot directly launch Windows applications, so you need to explicitly tell it which browser to use through an environment variable or helper script.
  • The BROWSER environment variable in your WSL shell profile tells command-line tools and scripts which browser to open.
  • You can point BROWSER to wslview (if available), powershell.exe, or a custom script that wraps a Windows browser path.
  • Setting this variable in your .bashrc or .zshrc file makes the change permanent across all new terminal sessions.

Using the BROWSER environment variable with wslview

The wslview command is a utility designed specifically to open URLs from WSL in your Windows default browser. It's available in recent versions of WSL 2 and handles the path conversion automatically. To use it, add this line to your WSL shell configuration file.

Open your .bashrc file (or .zshrc if you use Zsh) in a text editor:

nano ~/.bashrc

Add this line at the end of the file:

export BROWSER=wslview

Save the file (Ctrl+O, then Enter, then Ctrl+X in nano) and close your terminal. When you open a new WSL terminal, any program that tries to open a URL will use wslview, which passes it to your Windows default browser. This works with tools like Python's webbrowser module, Node.js packages, and command-line utilities.

Pointing BROWSER to PowerShell for direct Windows access

If wslview is not available on your system, you can use PowerShell to open links directly. This method works on any Windows 10 or 11 system with WSL 2 installed. The command tells PowerShell to use the Windows Start-Process cmdlet, which opens URLs in your default browser.

Add this line to your .bashrc or .zshrc instead:

export BROWSER='powershell.exe -Command "Start-Process"'

This approach is less elegant than wslview because it requires PowerShell to interpret each URL, but it's reliable and works across different Windows versions. The downside is that a PowerShell window may briefly appear when a link opens, depending on your system settings.

Creating a custom browser script for more control

If you need finer control—for example, to always open links in a specific browser rather than your default, or to handle multiple URLs—you can write a small shell script. This script acts as a bridge between WSL and Windows.

Create a new file called browser in your WSL home directory:

nano ~/browser

Paste this content:

#!/bin/bash for url in "$@"; do powershell.exe -Command "Start-Process '$url'" done

Save and close the file, then make it executable:

chmod +x ~/browser

Now add this line to your .bashrc:

export BROWSER=~/browser

This script accepts one or more URLs as arguments and opens each one in your default browser. You can modify the script to use a specific browser path instead of Start-Process—for example, replacing the PowerShell line with "/mnt/c/Program Files/Google/Chrome/Application/chrome.exe" "$url" to always use Chrome.

Opening a specific browser instead of your default

If you want to bypass your Windows default browser and always use a specific one, you can point BROWSER directly to that application's executable path. Browser executables live in /mnt/c/Program Files when accessed from WSL, because WSL mounts your Windows C: drive at /mnt/c.

For Chrome, add this to your .bashrc:

export BROWSER="/mnt/c/Program Files/Google/Chrome/Application/chrome.exe"

For Firefox:

export BROWSER="/mnt/c/Program Files/Mozilla Firefox/firefox.exe"

For Edge:

export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"

The exact path depends on your installation. If you're not sure where a browser is installed, open File Explorer in Windows, navigate to Program Files, and look for the folder. Spaces in paths need to be handled carefully—the quotes around the path protect them from being interpreted as separate arguments.

Testing your browser configuration

After you've set the BROWSER variable and restarted your terminal, test it with Python's webbrowser module:

python3 -c "import webbrowser; webbrowser.open('https://example.com')"

If your browser opens to example.com, the configuration is working. If nothing happens, check that your terminal session has reloaded the .bashrc file by typing echo $BROWSER—it should print the path or command you set.

If you see an error about the path not being found, double-check the spelling and location of the browser executable. Paths with spaces must be quoted, and paths to Windows drives must use the /mnt/c prefix.

Frequently Asked Questions

Why doesn't WSL open my browser automatically?

WSL is a Linux environment that doesn't have direct access to Windows applications. Linux programs expect a BROWSER environment variable to tell them which browser to use. Without it, they have no way to know how to reach your Windows browser.

Do I need to restart my computer after changing the BROWSER variable?

No. You only need to close your current WSL terminal and open a new one. Each new terminal session reads your .bashrc or .zshrc file and loads the updated variable. You don't need to restart Windows.

Can I use this with WSL 1, or only WSL 2?

This works with both WSL 1 and WSL 2. The main difference is that WSL 1 may be slower at launching Windows applications, but the BROWSER variable approach works the same way on both versions.

What if I want different browsers for different tasks?

You can create multiple scripts with different names and switch between them by changing the BROWSER variable, or you can write a script that checks the URL and opens different browsers based on the domain. For most use cases, setting one default browser is simpler.

Does this work with all programming languages and tools?

Most tools that open URLs respect the BROWSER environment variable, including Python, Node.js, Ruby, and many command-line utilities. Some applications may have their own configuration for which browser to use, so check the tool's documentation if setting BROWSER doesn't work.