Windows subsystem for linux is definitely a developers dream to have linux running with windows on official laptops. With all the restrictions around installation of VM and dual boot this comes as a life saver. Docker linux images did solve some of the problems but with WSL2, life is much more easier for working on windows host OS but developing and testing on linux. But there are few hiccups which we might have to encounter to get it working all togethor on official laptops.
- Preferred way of installing ubuntu WSL on windows 10 is to download it from Microsoft store as mentioned here. But there could be restrictions to download any app from store as was in my case. The help came from Microsoft itself. You can download it manually and steps are provided here. Don’t miss enabling virtual machine platform and creating user
- Once installed and machine restarted, you could see the installed distro in your start menu. For me its Ubuntu 20.04 LTS. But clicking on it gave me an exception as below. This is problem with the location.
C:\Program Files\WindowsApps\CanonicalGroupLimited.Ubuntu20.04onWindows_2004...\ubuntu.exe The service has not been started.
To Fix this just move the folder from Program files to a folder called unix under C: drive.
- Now you can just open a command prompt, navigate to folder containing ubuntu disto and start the ubuntu application under it. This would be your entry to linux world.
- You would need some basic applications like git and python3 for doing dev work here. You can always apt them but before that run the below command.
sudo apt update && sudo apt upgrade
- Now any service that runs under this linux env would be accessible from host windows env. To test it you can run below command and you would be able to access it from your windows browser by running http://localhost:8080
python3 -m http.sever 8080
- The next problem is to access URL’s which are within the company’s firewall from this linux env. Most of the companies use DHCP protocol to provide DNS names and other network properties to our machines, but in some cases these DNS names are not passed correctly to WSL2 linux env. The way to fix them is 2 step process
- Get all DNS Servers specified for all network adapters provided by ipconfig/all command and making sure all of them are present with nameserver tags in /etc/resolve.conf file.
- If some of them are missing, add those with nameserver tag in /etc/resolve.conf file name
** I believe there are better ways to do it , but other options didn’t work for me 😦
- The above step should solve the problem of finding hosts within corporate firewalls. But this might cause issues with connecting to internet world. To fix this you might have to set proxy which is used by your browsers. It could be easily found using chrome://net-export logs and tracing what proxy is used when you access http://www.google.com. Once found you can add them as below in your linux env. If you using bash, you can set it in ~/.bash_profile.
export http_proxy="<PROXY URL>" export https_proxy="<PROXY URL>"
This should fix all the issues and you can start playing with linux on windows 10.