List of content you will read in this article:
Windows Subsystem for Linux (WSL) is a popular feature in Windows 10/11 that allows users to run Linux commands and applications directly on their Windows machine. With the latest version, WSL2, users can also access the Linux file system natively and enjoy a more performant experience.
Installing WSL/WSL2 on Windows 10/11 is simple, but a few prerequisites and customizations can enhance the experience. In this step-by-step guide, we will walk you through installing WSL/WSL2 on Windows 10/11 and show you how to customize and troubleshoot it to make the most of this powerful feature.
What Exactly Is WSL and How Does It Work?
Windows Subsystem for Linux (WSL) is a feature in Windows 10/11 that allows users to run Linux applications directly on their Windows machines. It is essentially a compatibility layer between the Windows operating system and Linux, enabling users to access the Linux command-line interface and its tools. The technology behind WSL is essentially a virtualization layer that runs a Linux kernel inside a lightweight virtual machine, providing an isolated environment for Linux applications to run on Windows.
WSL translates Linux system calls to their corresponding Windows system calls, allowing Linux binaries to run seamlessly on Windows. The first version of WSL used a translation layer called lxcore.sys, which was a user-mode driver that could map Linux system calls to Windows system calls. The latest version, WSL2, uses a full Linux kernel in a lightweight virtual machine, which provides even better compatibility and performance for Linux applications.
WSL2 is designed to provide a more authentic Linux experience on Windows by supporting features like full system call compatibility, support for Docker, and access to the Linux file system natively. By running a Linux kernel inside a virtual machine, WSL2 provides an isolated and secure environment for running Linux applications on Windows. This allows developers and system administrators to work seamlessly between Windows and Linux environments without switching between the operating systems.
What Are the Uses and Benefits of WSL?
- Running Linux applications on Windows: One of the most obvious uses of WSL is the ability to run Linux applications natively on Windows. This can be especially useful for developers who must test their applications across multiple platforms.
- Developing cross-platform applications: With WSL, developers can easily switch between Windows and Linux environments and develop cross-platform applications without switching between the two operating systems. This can save time and increase productivity.
- Using Linux command-line tools on Windows: WSL provides access to the Linux command-line interface and its tools, which can benefit users who prefer Linux command-line tools over Windows command-line tools.
- Enhancing Windows with Linux tools: WSL allows users to enhance their Windows experience by using Linux tools like grep, sed, and awk, which are unavailable in Windows.
- Accessing the Linux file system from Windows: With WSL2, users can access the Linux file system natively from Windows, allowing them to work seamlessly between the two operating systems.
- Running Docker containers on Windows: WSL2 supports Docker, making it possible to run Docker containers on Windows and benefit from the advantages of both operating systems.
- Learning and experimenting with Linux: WSL provides a convenient way for Windows users to learn and experiment with Linux without installing a separate operating system.
- Faster performance and reduced resource consumption: WSL2 provides faster performance and reduced resource consumption compared to the first version of WSL, making it a more attractive option for users who need to run Linux applications on Windows.
- Easy installation and setup: WSL is easy to install and set up and can be done directly from the Microsoft Store.
- Free and open-source: WSL is a free and open-source technology, making it accessible to everyone and providing opportunities for customization and development.
Prerequisites of Installing WSL/WSL2
- Windows 10/11: WSL/WSL2 is a feature available only on Windows 10 and 11, so it is essential to have a compatible version of Windows installed on your machine.
- System requirements: The system requirements for WSL and WSL2 are relatively low, but it is recommended to have at least 4 GB of RAM and 64-bit Windows 10/11.
- Enable Virtualization: WSL2 requires virtualization to be enabled in your machine's BIOS/UEFI settings. Make sure to check if virtualization is enabled before installing WSL2.
- Update Windows: It is crucial to keep Windows up to date to ensure the latest security patches and updates are installed. Check for updates and install any available updates before installing WSL/WSL2.
- Disable Developer Mode: If Developer Mode is enabled on your machine, you will need to disable it before installing WSL/WSL2. To do so, go to Settings > Update & Security > For developers and select the option for "Sideload apps.
- Install Windows Terminal: Although not strictly necessary, Windows Terminal is a powerful terminal emulator that can enhance the WSL/WSL2 experience. Installing it beforehand can help you get started with WSL/WSL2 faster.
- Choose a Linux distribution: WSL/WSL2 requires a Linux distribution to be installed before it can be used. Microsoft provides several distributions in the Microsoft Store, including Ubuntu, Debian, and Fedora. Choose the distribution that best suits your needs and install it before proceeding with WSL/WSL2 installation.
- Install a Windows Subsystem for Linux update: Before installing WSL2, ensure you have installed the latest Windows Subsystem for Linux update. You can do this by checking for updates in the Microsoft Store or using the Windows Update feature.
- Enable Windows Subsystem for Linux: Before installing WSL/WSL2, you must enable the Windows Subsystem for Linux feature on your Windows machine. This can be done by going to Control Panel > Programs > Turn Windows features on or off and selecting the checkbox for Windows Subsystem for Linux.
- Install a Linux distribution: Choose the one you want to use and download it from the Microsoft Store. Once downloaded, launch the distribution and follow the setup wizard to install it.
- Install WSL2: To install WSL2, download and install the latest WSL2 kernel update package from the Microsoft website. After downloading the package, double-click it to run the installer and follow the setup wizard to install it.
- Set WSL2 as the default version: Once WSL2 is installed, you must set it as the default version. Open PowerShell or Command Prompt and enter the command: wsl --set-default-version 2
- Launch the Linux distribution: After installation, launch the Linux distribution from the Start menu or by typing its name in the Windows search bar. The first time you launch the distribution, setting up the environment may take a few moments.
- Customize the Linux environment: Once the Linux distribution is up and running, you can customize it by installing additional packages and configuring settings.
- Install additional tools: WSL/WSL2 provides access to a wide range of Linux tools and utilities, but you may need to install additional tools depending on your use case. You can install additional tools using the package manager for your Linux distribution.
- Access files and folders: By default, WSL/WSL2 can access only its file system, but you can access files and folders on your Windows machine using the /mnt directory. For example, to access the C: drive, use the command cd /mnt/c.
- Install and use Windows Terminal: Windows Terminal is a powerful terminal emulator that can enhance the WSL/WSL2 experience. You can download it from the Microsoft Store to manage multiple tabs and windows, customize settings, and more.
- Changing the default Linux distribution: If you have installed multiple Linux distributions, you can change the default distribution using the command: wsl --set-default <distribution name>.
- Changing the default user: By default, the user for a Linux distribution in WSL/WSL2 is set to the username you use on your Windows machine. You can change the default user by editing the /etc/wsl.conf file and adding the line user=<username>.
- Configuring the Linux environment: You can customize the Linux environment by editing the .bashrc or .zshrc files. These files are in your home directory and can be edited using a text editor.
- Installing additional software: WSL/WSL2 provides access to a wide range of Linux software, but you can install additional software using the package manager for your Linux distribution. For example, to install the git package in Ubuntu, use the command: sudo apt-get install git.
- Configuring network settings: You can configure network settings for WSL/WSL2 by editing the /etc/resolv.conf file. This file contains DNS server settings and can be edited using a text editor.
- Mounting Windows drives: WSL/WSL2 can access only its file system by default. However, you can mount Windows drives using the /mnt directory. For example, to mount the D: drive, use the command: sudo mount -t drvfs D: /mnt/d.
- Changing the default terminal: WSL/WSL2 uses the default Windows terminal. However, you can change the default terminal by setting the WSL_DISTRO_NAME environment variable to the name of the Linux distribution you want to use as the default terminal. For example, to use Ubuntu as the default terminal, use the command: setx WSL_DISTRO_NAME Ubuntu.
- Using GUI applications: WSL/WSL2 does not support GUI applications by default. However, you can install an X server on your Windows machine and use it to run Linux GUI applications. The most popular X server for Windows is Xming.
Tips & Tricks
- Using WSL with Visual Studio Code: If you are a developer, you can use Visual Studio Code with WSL/WSL2 to develop applications in a Linux environment. Visual Studio Code has built-in support for WSL/WSL2 and allows you to develop, build, and test applications in a Linux environment directly from your Windows machine. You can also install the Remote - WSL extension to access WSL/WSL2 directly from Visual Studio Code.
- Running GUI applications in WSL: Although WSL/WSL2 does not support GUI applications by default, you can install a third-party X server on your Windows machine and use it to run Linux GUI applications. One of the popular X servers for Windows is Xming. Once you have installed the X server, you can use the DISPLAY environment variable to run GUI applications in WSL/WSL2.
- Connecting to remote servers using SSH: WSL/WSL2 provides native support for SSH. SSH can connect to remote servers directly from your WSL/WSL2 terminal. To connect to a remote server using SSH, use the ssh command followed by the username and IP address of the remote server. For example, to connect to a remote server with the username user and the IP address 192.168.1.10, use the command: ssh firstname.lastname@example.org.
- Using Windows applications in WSL: Although WSL/WSL2 is designed to provide a Linux environment on Windows, you can also run Windows applications from within WSL/WSL2. To run a Windows application from within WSL/WSL2, use the cmd.exe command followed by the path to the Windows application. For example, to run Notepad from within WSL/WSL2, use the command: cmd.exe /c "start notepad".
- Sharing files between Windows and Linux: WSL/WSL2 provides a way to share files between Windows and Linux. By default, your Windows drives are mounted in the /mnt directory in WSL/WSL2. This allows you to access your Windows files from within WSL/WSL2. Similarly, you can also access your Linux files from within Windows using the \\wsl$\<distribution> path.
While installing WSL/WSL2 on Windows 10/11 is straightforward, some issues may arise during or after installation. Here are some common troubleshooting tips to help you resolve any issues you may encounter:
- Enable Virtualization: WSL/WSL2 requires virtualization support from your computer's processor. Ensure that virtualization is enabled in your computer's BIOS settings.
- Upgrade Windows: Ensure that you have the latest version of Windows installed. WSL/WSL2 is only available on Windows 10 version 2004 or later and Windows 11.
- Enable WSL/WSL2 feature: If you cannot install WSL/WSL2, ensure you have enabled Windows's WSL/WSL2 feature. To do this, open the Control Panel, select "Programs," then click "Turn Windows features on or off." Ensure that "Windows Subsystem for Linux" and "Virtual Machine Platform" are enabled.
- Check System Requirements: Ensure that your system meets the requirements for WSL/WSL2. WSL/WSL2 requires a 64-bit version of Windows 10 or 11 and a compatible version of Windows Build.
- Restart the Computer: Restarting your computer can sometimes help resolve installation issues.
- Check the Installation Logs: If the installation fails, check the installation logs to determine the cause of the issue. The installation logs are found at C:\Users\<Username>\AppData\Local\Temp\.
- Uninstall and Reinstall: If everything fails, try uninstalling and reinstalling WSL/WSL2.
- Check for Firewall Settings: Ensure your firewall is not blocking WSL/WSL2. You may need to add exceptions to your firewall settings.
- Check Antivirus Settings: Some antivirus software may interfere with installing WSL/WSL2. Check your antivirus settings to ensure it is not blocking WSL/WSL2.
- Check Network Settings: Ensure that your network settings are configured correctly. WSL/WSL2 requires an internet connection to download and install packages.
By following these troubleshooting tips, you should be able to install and use WSL/WSL2 on Windows 10/11 without any issues.
WSL/WSL2 is an incredibly useful tool that allows you to run Linux applications and commands natively on Windows 10/11. With this guide, you should now understand what WSL/WSL2 is, how to install it, and how to customize it to suit your needs. Whether you're a developer, a system administrator, or someone who wants to explore Linux on Windows, WSL/WSL2 is a powerful tool that can greatly enhance your workflow. Following the steps outlined in this guide, you should be able to install and use WSL/WSL2 on your Windows 10/11 machine in no time.
- WSL/WSL2 allows you to run Linux applications on Windows 10/11.
- WSL2 is a major improvement over the previous version, with a full Linux kernel.
- You can install multiple Linux distributions using WSL/WSL2.
- WSL/WSL2 can be customized to suit your needs, including running graphical applications and connecting to remote servers using SSH.
- Troubleshooting common issues, such as installation errors and networking problems, is an important part of using WSL/WSL2.