Article

Developing on Windows with WSL: A Guide to Streamlining Cross-Platform Development

June 14, 2024

By James Preston | Senior Software Engineer & Engineering Manager

I have a Windows desktop machine as well as a Mac book provided by my company. The Mac is great to carry with me, it’s lightweight and decently powerful.

However, when it comes to developing at home I like to use my Windows machine with its multiple monitors and extra horsepower. The problem, of course, has always been the slight differences in using the two machines to write code for the same project. We all know the actual writing of the code doesn’t vary but there are quite a few differences when it comes to installing any sort of package or plugins.  

A popular choice amongst many developers is Homebrew. Unfortunately you cannot use Homebrew natively on Windows. Homebrew is designed to work on macOS and Linux. There are alternatives like Chocolatey and Scoop but my goal is to be able to make both my Mac and Windows dev environments as close to the same as possible.

What is WSL?

Windows Subsystem for Linux (WSL) has emerged as a cornerstone tool for developers navigating the often turbulent waters of cross-platform development. It’s like a Swiss Army knife for developers working in a Windows environment who need the flexibility and power of Linux. 

  • Store files in an isolated Linux file system, specific to the installed distribution
  • Run command-line tools, such as BASH
  • Run Bash scripts and GNU/Linux command-line applications including:
  • Tools: vim, emacs, tmux
  • Languages: NodeJS, JavaScript, Python, Ruby, C/C++, C# & F#, Rust, Go, etc.
  • Services: SSHD, MySQL, Apache, lighttpd, MongoDB, PostgreSQL
  • Install additional software using your own GNU/Linux distribution package manager

Installing WSL

Open Powershell and run the following command. This will install WSL with a default Linux distro.

Using WSL VS Code

Install the WSL extension

You have 2 ways to open a project in vscode using WSL.

  1. Command Line
    a. Open the distributions command line and navigate to the location of the project and type code.

      2. VS Code
           a. Open the project in VS Code and hit Ctrl + Shift + P
           b. Type in WSL, there are various options including Reopen Folder in WSL

Why WSL?

Consistency and Compatibility

Consistency Across Platforms

Now that you have WSL running, you no longer need to worry about using Homebrew on Macs to install something like nodenv. While on the Windows machine, you either need to find an alternate way to do this or an alternate package which wastes time and potentially causes issues in the future.

Now that I am using WSL whether I am on my Mac or on my Windows machine, the same command will install the same package.

Seamless Transition Between Platforms

WSL enables developers to switch between Windows and Linux environments without breaking a sweat. This seamless transition caters to developers’ preferences for certain tools and utilities available on Linux.

Efficiency and Productivity

Efficient Onboarding and Environment Setup

Getting a new team member up to speed can be as simple as cloning a repository and running a few setup scripts. WSL allows for the creation of standardized development environments, meaning new developers can start contributing to projects without the hassle of configuring their machines for days. 

When a new team member comes on to the project, there is no longer a scramble for getting them a machine which matches the rest of the team. If they have a Linux or Mac they can just go. If they have Windows, they simply install WSL and then proceed just like the Linux and Mac developers.

Easy Environment Backup and Recovery

Gone are the days of fearing system crashes and losing your development environment. With WSL, backing up and recovering your environment is as straightforward as exporting and importing a WSL instance. This feature ensures that developers can easily migrate their work across machines or recover from unforeseen issues. You, also in theory, use this method to bootstrap your development environment but the setup is so easy without it that it seems best to me to keep this as a disaster recovery procedure.

Precise Environment Management

One advantage of WSL over a Mac or Linux environment is that you can have multiple distros installed and switch between them which are isolated from each other. 

Resource Efficiency

Optimizing Performance in WSL Environments

Designed with resource optimization in mind, WSL ensures that developers can run a fully-functional Linux environment on Windows without the overhead typically associated with virtual machines or dual-boot setups. 

Maximizing Performance

At the core of WSL’s philosophy is a commitment to maximizing the performance of both development environments. By minimizing the resource footprint of the Linux subsystem, WSL allows developers to run resource-intensive applications, compile large codebases, and perform heavy computational tasks without significant impact on their system’s overall performance. This efficiency is especially beneficial for developers working on high-demand projects or those who value a responsive and agile development environment. 

The ability to completely blur the line between the different machines the team is using and eliminating the “It works on my machine” issue which can plague teams using a different OS will have a huge impact on team performance.

Unprecedented Access to Linux Tools and Utilities

WSL demolishes the barriers between Windows and Linux by providing developers with unfettered access to Linux-specific utilities and package management systems such as apt, yum, and even Homebrew. Whether it’s installing a new library, setting up a development environment, or managing project dependencies, WSL ensures that these tasks are as straightforward as if you were operating directly on a Linux machine.

Enhanced Development Workflow with IDE Integration

The embrace of WSL by major Integrated Development Environments (IDEs) marks a significant leap forward in development tool integration. Leading IDEs, including JetBrains Rider and Visual Studio Code, offer robust support for WSL, enabling developers to leverage the strengths of both Windows and Linux development within a single, integrated environment. This support includes seamless code editing, debugging, and running applications directly within the IDE, all while interfacing with the Linux subsystem.

This integration is not just about convenience; it represents a paradigm shift in how development can be approached, combining the rich ecosystem of Linux development tools and libraries with the powerful features and familiarity of Windows. Developers can now enjoy a unified development experience that leverages the best of both worlds, eliminating the need to switch between systems or compromise on the choice of tools.

Community Support 

Strengthening WSL Through Simplified Issue Resolution

Within the development landscape, the Windows Subsystem for Linux (WSL) stands out not only for its seamless integration of Linux and Windows environments but also for its comprehensive approach to support and security. The journey of development is inherently dotted with challenges and stumbling blocks. However, the hallmark of a resilient and developer-friendly platform lies in how effortlessly these hurdles can be overcome. WSL distinguishes itself in this regard through simplified issue resolution, underpinned by robust community support and an emphasis on security.

Streamlined Troubleshooting with Community Insights

The essence of simplified issue resolution within the WSL ecosystem is deeply rooted in its vibrant community. Developers embarking on their WSL journey are never alone; they have at their disposal an extensive network of forums, social media platforms, and official documentation. This collective intelligence offers a streamlined approach to troubleshooting, ensuring that developers spend less time wrestling with issues and more time on innovation and development.

When developers encounter issues, whether they’re related to installation, configuration, performance optimization, or interoperability between Windows and Linux, the answers are often just a few clicks away. The community’s shared experiences serve as a beacon, guiding users through common pitfalls and beyond. This peer-supported ecosystem not only accelerates problem resolution but also enriches the developer’s knowledge, enabling them to tackle similar challenges with greater confidence in the future.

Leveraging Official Documentation and Resources

Microsoft’s commitment to WSL is evident in its comprehensive official documentation and resources, which serve as the cornerstone for support. This documentation is meticulously curated and regularly updated to reflect the latest advancements and fixes in WSL. It provides developers with a reliable source of truth for setup instructions, feature explanations, best practices, and security guidelines. By leveraging these resources, developers can ensure their WSL environment is not only optimized for their development needs but also secured according to best practices.

Security: A Top Priority in the WSL Ecosystem

Security is paramount in the development world, and WSL is designed with this in mind. The integration of WSL within the Windows ecosystem is engineered to uphold high security standards, ensuring that developers can work in a Linux environment without compromising the security of their Windows system. Regular updates and patches are part of Microsoft’s proactive approach to security, addressing vulnerabilities and enhancing features to protect developers and their work.

Developers are encouraged to follow security best practices recommended in the official WSL documentation. This includes keeping both Windows and WSL environments up to date, managing permissions carefully, and securing network communications. Moreover, the active community forums and social media groups often highlight emerging security concerns and solutions, fostering a culture of security awareness and collective vigilance.

The WSL community plays a crucial role in the platform’s security posture. Feedback from developers about security concerns and vulnerabilities is taken seriously, with many suggestions and reports leading to enhancements and patches. This collaborative approach to security ensures that WSL remains a safe, reliable platform for development activities.

Community and Support

The Heartbeat of WSL Success

Windows Subsystem for Linux (WSL) has become an indispensable tool for developers seeking the flexibility of Linux on a Windows platform. Beyond its technical prowess, the vibrant and supportive community surrounding WSL is a significant part of its success story. This community, composed of enthusiasts, professionals, and contributors from around the globe, forms the backbone of the WSL user experience. From forums and social media groups to official documentation, the ecosystem is rich with resources for both newcomers and seasoned developers.

Official Documentation: The Canonical Source

Microsoft’s official documentation for WSL is an invaluable resource for users at all levels. It not only offers comprehensive guides on installation, configuration, and usage but also delves into advanced topics such as integrating WSL with other Windows tools, optimizing performance, and troubleshooting. The documentation is continually updated to reflect the latest features and fixes, ensuring users have access to current and accurate information.

Blogs and Tutorials: Learning from Experts

The wealth of blogs and tutorials created by WSL users and experts is a testament to the community’s commitment to sharing knowledge. These resources range from basic how-tos and beginner guides to deep dives into complex topics. Whether you’re looking to set up a particular development environment, optimize WSL for performance, or explore new features, there’s likely a blog post or video tutorial that covers it.

Contribution and Collaboration: Shaping WSL’s Future

Finally, the WSL community is not just about receiving support but also about contributing to the ecosystem. Users can contribute in various ways, from reporting bugs and requesting features to contributing code and writing documentation. Microsoft’s GitHub repositories for WSL are open for contributions, and the feedback from the community plays a crucial role in shaping the future direction of WSL.

The WSL community is a dynamic and invaluable resource for anyone using WSL, regardless of their expertise level. The collective wisdom, enthusiastic support, and collaborative spirit found in forums, social media, official documentation, and blogs not only enhance the user experience but also drive continuous improvement and innovation in WSL. Whether you’re a beginner seeking guidance or an experienced developer looking to maximize the benefits of WSL, the community is there to support you every step of the way.

Conclusion

Developing on Windows using WSL is a game-changer for developers seeking the flexibility of Linux with the familiarity of Windows. By bridging the gap between these two platforms, WSL streamlines the development process, making it more efficient, secure, and enjoyable. Whether you’re working on a personal project or part of a large team, WSL is a tool worth exploring to enhance your development workflow.