Issue
Context:
I am using Ubuntu with WSL2 on Windows 11. When using e.g. AWS CLI to log in (e.g. via aws sso login
) it is necessary 1) to have access to the internet 2) be able to open a browser from the terminal.
Problem: The first problem is that I can't connect to the internet from the terminal. The second problem is once I connect successfully I get the error
xdg-open: no method available for opening
What do I need to do to successfully connect to the internet and open a browser window?
Solution
To connect to the internet I did the following:
sudo nano /etc/resolv.conf
- Change the IP address to
8.8.8.8
- Save the file
Unfortunately this has to be done on a regular basis. If someone knows how to have that set automatically respectively to avoid that I gets changed again please comment.
To open the default browser in Windows:
- Create a new script file:
nano ~/win-open.sh
- Add the following to the script. This script tells WSL to use cmd.exe (the Windows Command Prompt) to start the default application for the URL on Windows, which should be your default web browser.
#!/bin/bash
cmd.exe /c start $1
- Make the script executable:
chmod +x ~/win-open.sh
Then configure xdg-open to use the script
- Edit your .bashrc or .zshrc file (depending on your shell):
nano ~/.bashrc
ornano ~/.zshrc
- Add the following line at the end of the file:
export BROWSER=~/win-open.sh
- Reload the Configuration:
source ~/.bashrc
orsource ~/.zshrc
Then you can test e.g. with xdg-open https://www.google.com
.
Answered By - quervernetzt Answer Checked By - Marie Seifert (WPSolving Admin)