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.
- 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.
- 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.
- Use Windows Terminal instead of Cmder, ConEmu, Mintty, Cygwin 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.
- 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.
-- --
- 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.
- 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.
- If you are into using tmux, you can use that too in your WSL 2, and power it up with tmux-powerline.
- 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. - 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.
- 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.
References