WSL can open your browser, but you have to tell it how
When you run a web development server inside Windows Subsystem for Linux (WSL), you often want to view the result in your browser on Windows. By default, WSL does not know how to launch your browser — it runs in an isolated Linux environment and cannot directly call Windows programs. You have to configure WSL to pass browser commands back to Windows, which takes a few minutes and works the same way whether you use WSL 1 or WSL 2.
The simplest method is to set an environment variable that tells WSL which browser command to use. This variable points to a Windows executable, and WSL translates the request so Windows can open it. Once set, commands like xdg-open http://localhost:3000 will launch your default browser automatically.
Key Takeaways
- WSL cannot open Windows programs directly, so you must configure it to pass browser commands to Windows using an environment variable.
- The BROWSER environment variable tells WSL which program to use when you ask it to open a URL.
- You can set this variable permanently in your WSL shell configuration file so it persists every time you open WSL.
- After configuration, typing xdg-open http://localhost:3000 in WSL will open that URL in your Windows browser.
- If your browser does not open, check that the path to the executable is correct and that you used forward slashes in the path.
Find the path to your browser executable on Windows
Before you configure WSL, you need the full path to your browser's executable file on Windows. The most common browsers are installed in predictable locations, but the exact path depends on which browser you use and whether you installed it for all users or just your account.
For Google Chrome, the path is usually C:\Program Files\Google\Chrome\process\chrome.exe or C:\Program Files (x86)\Google\Chrome\process\chrome.exe on older systems. For Microsoft Edge, it is typically C:\Program Files (x86)\Microsoft\Edge\process\msedge.exe. For Firefox, look for C:\Program Files\Mozilla Firefox\firefox.exe or C:\Program Files (x86)\Mozilla Firefox\firefox.exe.
If you are not sure, open File Explorer on Windows, navigate to C:\Program Files, and look for a folder with your browser's name. Open it and find the executable file — it will have a .exe extension and usually matches the browser name. Once you find it, copy the full path including the filename.
Open your WSL shell configuration file
To make the browser setting permanent, you need to add it to your shell's configuration file. This file runs every time you open WSL, so any variables you set there will be available automatically. The file you edit depends on which shell you use — most WSL installations use bash by default.
Open WSL and type the command below to open your shell configuration file in a text editor:
nano ~/.bashrc
If you use zsh instead of bash, type nano ~/.zshrc. The nano editor will open the file in your terminal. If the file is empty, that is normal — it just means you have not added custom settings yet.
Add the BROWSER variable to your configuration
At the bottom of the file, add a new line with the BROWSER variable pointing to your Windows browser. Use the path you found earlier, but replace all backslashes with forward slashes. WSL understands forward slashes even though Windows uses backslashes.
For Chrome, add this line:
export BROWSER="/mnt/c/Program Files/Google/Chrome/process/chrome.exe"
For Edge, use:
export BROWSER="/mnt/c/Program Files (x86)/Microsoft/Edge/process/msedge.exe"
For Firefox, use:
export BROWSER="/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
Notice that the path starts with /mnt/c — this is how WSL accesses your Windows C: drive. If your browser is installed on a different drive, replace c with the correct drive letter.
Save the file and reload your configuration
In the nano editor, press Ctrl+O to save the file. Press Enter to confirm the filename, then press Ctrl+X to exit the editor. You are now back at the WSL command prompt.
To load the new configuration without closing and reopening WSL, type:
source ~/.bashrc
If you edited .zshrc, type source ~/.zshrc instead. The configuration is now active in your current session and will load automatically every time you open WSL in the future.
Test that your browser opens from WSL
To verify the configuration works, start a straightforward web server in WSL. If you have Python installed, navigate to any folder and type:
python3 -m http.server 8000
This starts a test server on port 8000. In another WSL terminal window, type:
xdg-open http://localhost:8000
Your Windows browser should open and display the directory listing from that folder. If it does not, check that the path to your browser is correct and that you used forward slashes instead of backslashes. If the path contains spaces, make sure it is wrapped in quotes as shown in the examples above.
Troubleshoot if the browser does not open
If xdg-open does not launch your browser, the most common cause is an incorrect path. Verify the path by opening File Explorer on Windows, navigating to the folder where your browser is installed, and copying the full path from the address bar. Then check that you replaced all backslashes with forward slashes and added /mnt/c at the beginning.
Another common issue is that the BROWSER variable is not being read. Type echo $BROWSER in WSL to see what value is currently set. If it shows nothing or an old value, you may have edited the wrong configuration file. Check whether you use bash or zsh by typing echo $SHELL, then edit the correct file.
If you installed your browser in a non-standard location or under your user profile rather than Program Files, the path will be different. Navigate to that location in File Explorer, copy the full path, and update the BROWSER variable with the correct path.
Frequently Asked Questions
Do I need to do this for every WSL distribution I install?
Yes. Each WSL distribution has its own separate filesystem and configuration files. If you install Ubuntu and Debian, you will need to add the BROWSER variable to the .bashrc file in each one. The process is identical — only the distribution you are working in changes.
Can I use a different browser than my Windows default?
Yes. The BROWSER variable lets you specify any browser you want, regardless of which one is set as your Windows default. Just point it to the executable of whichever browser you prefer, and WSL will use that one when you run xdg-open.
What if I want to open a file instead of a URL?
The xdg-open command works with file paths too. Type xdg-open /path/to/file.html and it will open that HTML file in your configured browser. This is useful when you want to preview a local file without running a server.
Will this work with WSL 2?
Yes. The BROWSER variable method works with both WSL 1 and WSL 2. WSL 2 runs a lightweight virtual machine, but it still has access to your Windows filesystem through the /mnt path, so the configuration is identical.
Can I set a different browser for different projects?
Yes, but you would need to override the BROWSER variable in each project's shell session. You could create a script that sets BROWSER to a specific browser before starting your development server, or you could manually type export BROWSER="/path/to/browser" in a specific terminal window before running commands.