5 Best Practices for Using WSL 2 on Windows 10/11

Microsoft has introduced nifty features to Windows 10 and 11 in recent years, but for the developer community, Windows Subsystem for Linux 2 is probably the standout feature.

Based on the original WSL, the newer WSL 2 brings more power and reliability to developers. Developers must know how to get the most out of WSL 2.

The following article will discuss some best practices for using Windows Subsystem for Linux 2.

1. Using Windows Terminal

The all-new Windows Terminal is a powerful open source terminal from the Microsoft Store. Microsoft designed Windows Terminal to integrate WSL 2 directly and automatically configure all Linux distributions as soon as they are installed. This means you can easily switch between Windows and Linux without having to set up another environment.

5 Best Practices for Using WSL 2 on Windows 10/11 Picture 15 Best Practices for Using WSL 2 on Windows 10/11 Picture 1

Windows Terminal can support many shells, such as PowerShell, WSL 2, and Command Prompt. It also offers a number of productivity features, including multiple tabs, a search bar, and a split pane; you can even customize the look and feel of the terminal to your liking.

 

Since Windows Terminal is an open source project, you can rest assured that the community will continuously improve it to enhance the user experience.

2. Visual Studio Code Integration

5 Best Practices for Using WSL 2 on Windows 10/11 Picture 25 Best Practices for Using WSL 2 on Windows 10/11 Picture 2

Many developers rely on VS Code, an extremely flexible IDE (code editor). It offers an integrated terminal, supports extensions, and has a super customizable visual interface. If you're using WSL 2 for development, you'll want to integrate WSL 2 with Visual Studio Code for a smooth workflow.

You can use VS Code with WSL 2 by making sure you have Visual Studio Code and a WSL 2 Linux distribution on your Windows system. You can install the Remote - WSL extension in Visual Studio Code and configure it according to your requirements.

3. Set up multiple profiles

If you plan to use WSL 2 for work, personal study or school, consider creating your own user profile. This will allow you to organize your apps, profiles, and files.

 

One method for setting up multiple profiles is to use the Windows Terminal; once you have it installed on your PC running Windows 10 or 11, navigate to Settings > Profiles > Add .

4. Update package

Like any other Linux distribution, you'll have to make sure the packages and tools you're using on WSL 2 are kept up to date. Doing so ensures your WSL 2 is safe, reliable, and operating optimally. To update packages on WSL 2, enter the following command:

sudo apt-get update
sudo apt-get upgrade

5. Run Containers with Docker

5 Best Practices for Using WSL 2 on Windows 10/11 Picture 35 Best Practices for Using WSL 2 on Windows 10/11 Picture 3

Docker is an open source platform that allows developers to efficiently build, deploy, and run their applications in containers. All dependencies are grouped so that your project can be easily deployed in any environment.

You can use Docker on Windows 10 and 11 through Docker Desktop as a standalone application, or integrate it with Windows Subsystem for Linux for better performance and efficient resource consumption. The article strongly recommends running your container with WSL 2 for development or testing.

Windows Subsystem for Linux 2 is amazing and effectively bridges the gap between the Linux and Windows ecosystems. As a developer familiar with Windows, you can leverage WSL 2 to get the best out of both Windows and Linux without compromising your productivity or flexibility.

4.7 ★ | 3 Vote