WSL: The Perfect Blend of Linux Command Line and Windows Interface for Developers

Ahmed RazaAhmed Raza
5 min read

The Windows Subsystem for Linux (WSL) is a powerful tool that enables developers to run a Linux distribution directly on Windows, without the need for a dual-boot setup or virtual machine. As web development increasingly leverages Linux-based tools, WSL has become an essential tool for developers working on Windows. In this article, we will explore why WSL is preferred in web development, how to install it, and how to integrate it with Visual Studio Code for a streamlined development experience.

Why WSL is Preferred in Web Development

  1. Access to Linux Tools and Environments: Many modern web development tools are designed to work seamlessly on Linux-based systems. From package managers like apt to containers using Docker, many of these tools are either unavailable or have limited support on Windows. WSL allows developers to run a Linux distribution on top of Windows, providing full access to a Linux command-line environment, all while maintaining the ability to work with Windows applications.

  2. Improved Performance: Before WSL, developers using Windows had to rely on virtual machines (VMs) or dual-boot systems to run Linux-based tools. VMs consume significant system resources and can degrade performance. WSL, especially in its latest version (WSL 2), uses a lightweight virtualization technique that offers near-native performance, improving the speed and responsiveness of web development tasks.

  3. Consistency Across Development Environments: With WSL, developers can replicate the same Linux-based environments used in production, which ensures that there are no discrepancies between development and production environments. This is particularly crucial for web development teams working with deployment services like AWS, Google Cloud, or DigitalOcean, where Linux is the primary operating system.

  4. Seamless Integration with Windows: WSL provides deep integration with the Windows operating system, allowing developers to work on the same files across both environments. Developers can edit code in Windows, run Linux-based tools, and easily transfer files between the two environments. This integration creates a fluid, cross-platform development experience.

How to Install WSL on Windows

To get started with WSL, follow these steps:

  1. Enable WSL on Windows:

    • Open PowerShell as an administrator by right-clicking the Start button and selecting Windows PowerShell (Admin).

    • Run the following command to enable WSL:

        wsl --install
      

      This command installs WSL and downloads the latest Linux kernel. If you're on an older version of Windows, you may need to enable it manually through the Windows Features dialog.

  2. Install a Linux Distribution: Once WSL is enabled, you can install your preferred Linux distribution from the Microsoft Store. Some of the most popular distributions include Ubuntu, Debian, and Kali Linux.

    • Open the Microsoft Store and search for a Linux distribution (e.g., Ubuntu).

    • Click Install and wait for the installation to complete.

  3. Set Up Your Linux Distribution: Once the distribution is installed, launch it from the Start Menu. The first time you open it, you'll be prompted to set up your user account and password.

  4. Upgrade to WSL 2 (Optional but Recommended): WSL 2 is the latest version of the Windows Subsystem for Linux and offers improved performance and full system call compatibility with Linux. To upgrade to WSL 2, run the following commands:

     wsl --set-default-version 2
    

    Then, you can verify your version by running:

     wsl --list --verbose
    

Using Visual Studio Code with WSL

Visual Studio Code (VS Code) is one of the most popular code editors among web developers, offering a rich set of features like debugging, version control, and a large collection of extensions. When combined with WSL, VS Code can provide a highly efficient development environment that brings the power of Linux tools directly into the Windows workspace.

Steps to Set Up Visual Studio Code with WSL:

  1. Install Visual Studio Code: If you haven’t already, install Visual Studio Code by downloading it from the official website: Visual Studio Code.

  2. Install the WSL Extension for VS Code:

    • Launch Visual Studio Code.

    • Go to the Extensions view by clicking the Extensions icon in the Activity Bar on the side of the window.

    • Search for the Remote - WSL extension and click Install.

  3. Open a Project in WSL:

    • Once the extension is installed, open a new WSL window by clicking on the green \>< icon in the lower-left corner of VS Code, and select Remote-WSL: New Window.

    • You can now open any folder within the WSL environment by selecting File > Open Folder and navigating to your Linux file system (typically located under /home/<your-username>).

  4. Install Additional Extensions (Optional): Depending on your development needs, you can install a variety of extensions to enhance your workflow within WSL. Extensions like Python, Node.js, Docker, and Git can be installed to facilitate smooth development directly inside the WSL environment.

  5. Edit Code and Run Commands: With the WSL integration, you can open and edit files directly within the Linux file system using the full power of VS Code's editor. You can also run Linux-based commands (e.g., npm, git, docker) directly in the integrated terminal in VS Code, eliminating the need to switch between Windows and Linux environments.

Conclusion

The Windows Subsystem for Linux (WSL) has become an indispensable tool for web developers working on Windows. By providing access to Linux-based tools, seamless integration with Windows, and improved performance, WSL bridges the gap between the two ecosystems. When combined with Visual Studio Code, developers can enjoy an efficient, cross-platform workflow that allows them to leverage the best of both worlds. Whether you're developing with Node.js, Python, or working with Docker containers, WSL streamlines your web development process and provides an environment that closely mirrors production systems.

0
Subscribe to my newsletter

Read articles from Ahmed Raza directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ahmed Raza
Ahmed Raza

Ahmed Raza is a versatile full-stack developer with extensive experience in building APIs through both REST and GraphQL. Skilled in Golang, he uses gqlgen to create optimized GraphQL APIs, alongside Redis for effective caching and data management. Ahmed is proficient in a wide range of technologies, including YAML, SQL, and MongoDB for data handling, as well as JavaScript, HTML, and CSS for front-end development. His technical toolkit also includes Node.js, React, Java, C, and C++, enabling him to develop comprehensive, scalable applications. Ahmed's well-rounded expertise allows him to craft high-performance solutions that address diverse and complex application needs.