Getting Started with Development in Windows

Getting Started with Development in Windows

Microsoft has been doing great stuff for years now, and WSL2 (Windows Subsystem for Linux - 2) is everything that I personally neeeded to feel completely at home as a developer in Windows. WSL2 allows you to run a full fledged Linux kernel with greatly improved IO and support, as compared to WSL1. WSL2 connects flawlessly with a Windows installation of Visual Studio Code and supports Docker natively. In short, your Windows setup would serve you well in your development endeavors.

In this article, I’ll discuss how to get WSL2 up and running on your system along with an integration with - Windows Terminal and Visual Studio Code.

Pre-requisites

The sole major pre-requisite for installing WSL2 is a Windows installation version 2004, with a build higher than or equal to 19041. You can check your Windows installation version by pressing - Windows Logo + R. If your Windows version does not match the requirements there is no need to fret, you can freely upgrade your Windows to the required version by following the listed steps:

  1. Install updates available for your Windows by clicking here. Post installation, check your Windows version again, if it meets the requirement, you can skip step 2 and move on to WSL2 Installation, if it doesn’t step 2 will get you up to speed quickly.
  2. If updates for your Windows does not include an upgrade to version 2004, you can do so manually, by installing Windows Update Assisstant. Run the Update Assisstant and follow instructions to update Windows to the May, 2020 release – version 2004.

WSL2 Installation

By this point, I am assuming that you have Windows 10 version 2004 up and running, if you haven’t done so, this is a crucial pre-requisite and you should follow the steps mentioned in the previous section before coming here. If you’ve done so, follow the steps mentioned below to complete your WSL2 installation:

  1. Open Windows PowerShell as an administrator and run the following commands:
    1
    2
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  2. Restart your system.
  3. Download and run the WSL2 Linux Kernel update package. Ensure that the package successfully installs before moving forward.
  4. Download and install a linux distribution of your choice from the Microsoft Store.
  5. Setup your new installation by creating a username and a password.
  6. Check which version of WSL your distribution is using by running the following command in Windows PowerShell:
    1
    wsl --list --verbose
  7. To set your linux distribution ot choose WSL2 instead of WSL1, run the following command in Windows PowerShell – (set distribution name to your distribution name, and versionNumber to 2):
    1
    wsl --set-version <distribution name> <versionNumber>
  8. Run the following command to set the default WSL version to 2 for new linux installations :
    1
    wsl --set-default-version 2
  9. If you face any errors in your installation, you can check Windows instllation guide.

Visual Studio Code

Visual Studio Code is one of the best, if not the outright best, code editors out there. Lightning fast, with a plethora of plugins and connections and lot of themes and customizations – there aren’t a lot of reasons to not use it. In this section, we’ll install Visual Studio Code and connect it with your WSL2 installation. Follow the steps mentioned below:

  1. Download and install Visual Studio Code on your Windows PC. PS : Do NOT install it on your WSL2 based Linux distribution.
  2. Lauch Visual Studio Code when it finishes installing and download the Remote-WSL extension.
  3. And that’s it! Your VSC installation should be up and running on Windows with a WSL connection. If you face issues in installation, you can refer to Microsoft’s installation documentation.

Windows Terminal

Windows Terminal is a powerful shell for your linux distributions which enables you to access them from one single application in a highly customizable setup. To install and setup Windows Terminal, follow the steps mentioned below:

  1. Download and install Windows Terminal from the Microsoft Store.
  2. Launch Windows Terminal, click on the downward-arrow in the tab bar and click on settings.
  3. The previous step would open a settings.json file that stores configurations for your Windows Terminal. Select the “guid” of your most used linux distribution installation and paste it against the “defaultProfile” key. This would load your chosen distribution everytime you open a new Terminal tab.
  4. Terminal by default open in you Windows home folder, to change this to your Linux home, add a cd to your linux bash profile. Do the following from your linux shell:
    1
    2
    3
    4
    vim ~/.bashrc
    # add a new line and enter 'cd' in it
    # save the file by pressing :wq
    # restart your linux terminal

Conclusion

And you’re done! You’ve successfully setup a Windows Development Environment complete with VSC, WSL2 and Terminal. If you face any issues in any of the installations, feel free to reach out to me on vivek.kaushal@outlook.com.

Getting Started with Development in Windows

http://vivekkaushal.com/2020-08-18-windows-setup/

Author

Vivek Kaushal

Posted on

2020-08-18

Updated on

2020-10-20

Licensed under

Comments