Buy @ Amazon

WSL For Development In Windows 10 Is The New Kool-Aid

I had been a happy-go Java developer on Windows platform. And then I had to ride the Ruby-on-Rails wave over Linux platform, only to realize how much I didn't know about productivity with automation. Later I moved onto MacOS to experience bliss before starting to hate it for one thing after the other; right from their buggy operating system upgrades to Apple not providing power cable compatible to Indian market resulting in earthing issues. Out of frustration I jumped back to Ubuntu and now back on Windows after long years. 

Getting onto Windows was more out of necessity than interest and I started to explore how much things have changed in the Windows world. It wasn't a smooth return for me but the teething period is over and I'm loving Windows again. If you are onto Windows 10 Pro edition, and wanting to get the best of both worlds (Windows and Linux), this post is for you. I am jotting down ProTips to experience delight and productivity at development work.
  1. Use WSL 2 instead of WSL 1, for the former is far less resource intensive by integrating natively with Windows 10 Hyper-V virtualization stack, and thus phenomenally faster too. If you are on Windows 10 Home edition, you need to upgrade it to Windows 10 Pro edition and it is worth it, for you can get it at half the price upon upgrade.
  2. Do not mount windows native formatted drive (NTFS) onto WSL for code that can be developed both in WSL environment and Windows. While this works, it is snail paced and you will frustrated too soon. I tried this out of curiosity and frustrated beyond my anticipation. If you are still wanting this, you will have to first format the storage drive in DOS format (as FAT32), so that it works well with your WSL and host Windows operating systems. This is possible the best middle-ground that you can hit upon.
  3. Use Windows Terminal instead of  CmderConEmuMinttyCygwin or any other console emulators. Why? You can customize it with default settings for each of WSLs, Windows Command Prompt, Powershell or other terminals integrated with it. Also Windows Terminal is lightweight and faster.
  4. When you start your development server in WSL 2, try testing it in your browser with localhost, it won't work. WSL is one proper sandboxed environment or VM. You need to port forward localhost settings for this to work. This can be done by adding the line like below in your .wslconfig file in your windows $HOME directory.
    -- --
  5. WSL 2 can consume all of your host memory. You can set limits to it by appending the line memory=16GB in your .wslconfig file.
  6. Do install Oh-My-ZSH to use zsh shell instead of the default bash. You get bunch of goodies like pre-configured aliases for Git and more by way of its plugins that you can configure to your preference.
  7. If you are into using tmux, you can use that too in your WSL 2, and power it up with tmux-powerline.
  8. You can change the location of your WSL 2 distribution's virtual hard drive. I keep all of my VMs (and now WSL 2 virtual hard drives) in D:\VMs\<platform>\<distribution name>. Run the following commands in PowerShell - replacing distribution name and preferred location:
    ----
    Also at the time of writing, when you import a distribution, you may need to tell WSL 2 to start the distribution using the Linux user account you created when you first created the distribution. Thanks to 58bits.com that you can run the below PowerShell script that imports the distribution, and resets the default user as you would like it to be.
    -- --
    Note that if your import fails with 'Unspecified error' (or other) - you may need to limit the amount of memory allocated to vmmem. You can do this with WSL2 config to limit memory as mentioned in ProTip 5 above.
  9. If you are into using VS-Code as your IDE for development, you can launch the one you installed on your host Windows 10 OS from WSL 2 bash in your project's root folder and executing `code .`. With this you can work on your windows operating system launching your development servers in WSL environment, thus getting the best of both the worlds. Additionally, you can install your vs-code extensions on remote wsl as well as on host OS, all from within your IDE.
  10. And Docker Desktop for Windows works well with your WSL2 too. You just can extract the best from everything. 
Upcoming Feature: Having dual boot for Windows and Linux? You can mount your linux partitions onto WSL2 in Windows 10. Checkout Microsoft Dev Blogs

Windows 10 is super cool again with WSL 2. Whether you are a Windows buff wanting to leverage Linux goodies, or a Linux buff wanting to draw upon Windows 10 strengths, you can have it all. Happy coding!!..

References