When using the Windows Subsystem for Linux (WSL), you may encounter situations where you need to open links from the command line. By default, WSL does not have a built-in mechanism to handle opening links, so you'll need to configure it to use a specific browser or application. In this article, we'll explore how to set default values for opening links in WSL.
Choosing a Default Browser
The first step is to choose a default browser that you want to use for opening links in WSL. This can be any browser installed on your Windows operating system. The most common browsers include Google Chrome, Mozilla Firefox, and Microsoft Edge. Once you have selected a browser, you can proceed with the configuration.
Configuring WSL to Use a Default Browser
To configure WSL to use a default browser, you need to modify the ~/.bashrc file in your Linux distribution running on WSL. Follow these steps:
- Open your preferred Linux distribution in WSL.
- Launch a text editor such as
nanoorviby typing the command in the terminal. - Locate and open the
~/.bashrcfile. - Add the following lines at the end of the file to set the default browser:
export BROWSER=/mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe
Replace the path in the above command with the actual path to the browser executable on your system. Make sure to escape any spaces in the path using a backslash (\).
Save the changes and exit the text editor.
Now, whenever you open a link from WSL, it will be automatically opened in the browser you specified as the default.
Using a Different Application
If you prefer to open links in an application other than a web browser, you can also configure WSL to use that application. Here's how:
- Open your preferred Linux distribution in WSL.
- Launch a text editor such as
nanoorviby typing the command in the terminal. - Locate and open the
~/.bashrcfile. - Add the following lines at the end of the file to set the default application:
export BROWSER=/mnt/c/Path/To/Application.exe
Replace the path in the above command with the actual path to the application executable on your system. Again, remember to escape any spaces in the path using a backslash (\).
Save the changes and exit the text editor.
Now, when you open a link from WSL, it will be opened in the application you specified as the default.
Verifying the Configuration
To verify that the default browser or application has been set correctly, you can use the xdg-open command. This command is used to open a file or URL using the default application specified in the system.
Open a terminal in WSL and type the following command:
xdg-open https://www.example.com
If the default browser or application is configured correctly, the specified URL will be opened in the browser or application you set as the default.
Configuring default values for opening links in WSL is a simple process that allows you to seamlessly open links from the command line. By setting a default browser or application, you can enhance your workflow and make it more efficient.
References
| Source | Link |
|---|---|
| WSL Documentation | https://docs.microsoft.com/en-us/windows/wsl/ |
| Linux man pages | https://man7.org/linux/man-pages/ |