WSL does not have a built-in default browser for opening links from the command line. The behavior depends entirely on whether you are using the wslu package or a specific Windows build that supports native URI handlers. To configure this, you must install the appropriate helper tools and set environment variables to point to the correct execution path.
Understanding the Default Behavior
When you type a URL into a terminal running inside Windows Subsystem for Linux (WSL), the system needs a bridge to communicate with the Windows host operating system. By default, modern versions of WSL2 attempt to use a mechanism calledwslview. However, this utility is not included in the base Ubuntu or Debian images installed via the Microsoft Store. If you do not have the necessary packages installed, attempting to open a link will result in a "command not found" error.
The confusion often arises because users expect the Linux environment to know which browser is set as their default in Windows. It does not. The Linux kernel has no access to the Windows Registry or the user's preferred application settings by default. Therefore, the "default value" is effectively null until you explicitly configure a handler. This setup is distinct from general disk space management or remote desktop configurations, which are separate subsystems within the WSL architecture. For more information on managing your WSL installation, see our guide on Why is WSL taking up more disk space than it says it is?.
Method 1: Using the wslu Package (Recommended)
The most robust and widely supported method for handling URLs in WSL is using thewslu utilities. This package provides a suite of tools designed specifically to bridge the gap between Linux commands and Windows capabilities. It includes wslview, which can handle various URI schemes including HTTP, HTTPS, and file paths.
To implement this solution, follow these steps:
- Install the wslu package: Open your Ubuntu terminal and run the following command to update your package list and install the utilities. You may need to use
sudodepending on your user permissions.
sudo apt update
sudo apt install wslu
- Verify Installation: After installation, verify that the
wslview command is available by typing wslview --help. This should display usage instructions without throwing an error.
wslview --help
- Test the Configuration: Now, try opening a simple website by running
wslview https://www.example.com. The browser configured as your default in Windows should launch automatically.
Method 2: Native URI Handling in Newer Builds
Microsoft has been working on integrating native URI handling directly into the WSL kernel interface. In certain newer builds of Windows 11 and updated WSL versions, the system may automatically detect and open URLs if they are passed correctly. However, relying solely on this feature can be risky because it depends heavily on your specific Windows version and the current state of the WSL update channel. If you find thatwslview is not recognized and you are on a very recent build, check if the system responds to direct URL arguments in standard commands. For example, some text editors like nano or vim might trigger a browser open if linked properly, but this is inconsistent. The safest approach remains installing wslu as described above. If you encounter issues with your WSL installation after updates, refer to our troubleshooting guide for Fixing WSL Not Working After Moving Ubuntu from C to D, as permission changes can sometimes break external tool integrations.
Customizing Browser Preferences
Since WSL relies on the Windows host for rendering web content, your browser choice is determined by Windows settings, not Linux settings. To change which browser opens when you click a link in WSL, you must adjust your default apps in Windows. Navigate to Settings > Apps > Default apps in Windows. Select your preferred browser (e.g., Chrome, Firefox, Edge) and set it as the default for HTTP and HTTPS protocols. Once this is done, any call towslview from your WSL terminal will respect this Windows-level configuration. There is no need to modify environment variables in .bashrc or .zshrc unless you want to create custom aliases for convenience.
For instance, you can add the following line to your shell configuration file to make opening URLs faster:
alias browse='wslview'
After saving the file, reload your shell with source ~/.bashrc. You can now simply type browse google.com to open Google in your default browser. This alias approach is particularly useful if you frequently switch between different browsers for testing purposes.
Troubleshooting Common Issues
Even withwslu installed, you may encounter situations where links fail to open. The most common cause is a mismatch between the WSL distribution and the Windows build. Ensure that your WSL version is up to date by running wsl --update in PowerShell or Command Prompt.
Another potential issue involves network permissions. If your corporate firewall blocks outgoing connections from WSL, the browser may hang while trying to resolve the domain. In such cases, verify that your Windows firewall allows inbound and outbound traffic for your chosen browser. Additionally, ensure that you are not running multiple instances of the same browser that might conflict with the URI handler registration.
If you are migrating your WSL environment, such as transferring it to a USB drive, be aware that registry keys and environment variables might not carry over seamlessly. Always reinstall wslu after moving your installation to ensure the binary paths are correctly registered in the new environment. See our guide on Can I Transfer My WSL Ubuntu Installation to a USB and Run It from There? for details on migration best practices.
Frequently Asked Questions
Does WSL 1 support wslview?
No, wslview is primarily designed for WSL 2 due to its reliance on the improved interoperability features between Windows and Linux. WSL 1 uses a different translation layer that may not support these external utilities as effectively. Upgrading to WSL 2 is recommended for full URL handling support.
Can I open local HTML files from WSL?
Yes, wslview can open local file paths. Simply pass the absolute path to the HTML file, such as wslview /mnt/c/Users/Name/Documents/index.html. The browser will render the local page just as it would a remote URL.
What if my default browser is Edge but I want Chrome?
You cannot force a specific browser from within Linux alone. You must change your default browser setting in Windows Settings. Once Windows is configured to use Chrome for HTTP/HTTPS, all wslview calls will automatically open Chrome.
Is there a way to open links in a specific tab of an existing browser window?
Standard wslview functionality does not support attaching to existing browser tabs. It typically launches a new window or tab depending on your browser's default behavior. Advanced scripting would be required to achieve this, which is beyond the scope of basic WSL configuration.
Why does wslview fail after a Windows update?
Windows updates can sometimes reset default app associations or update WSL components that temporarily break compatibility. Re-running wsl --update and verifying your default browser settings in Windows usually resolves the issue. If problems persist, reinstalling the wslu package ensures you have the latest binaries.