How To Install Windows Subsystem for Linux on Windows 11

The Windows Subsystem for Linux (WSL) allows you to run Linux environments and applications directly on Windows. With WSL, you can have the best of both worlds – the familiar Windows interface combined with the power of Linux.

Installing WSL on Windows 11 is easy and only takes a few steps. In this comprehensive guide, we’ll walk you through the entire process of setting up WSL step-by-step. We’ll also provide tips and tricks for optimizing WSL for the best performance.

Prerequisites

Before installing WSL, you need to ensure your Windows 11 system meets the following requirements:

  • You must be running Windows 11 version 22000.0 or higher. To check your version, go to Settings > System > About.
  • Your Windows installation must be 64-bit. WSL is not supported on 32-bit versions of Windows.
  • Virtual Machine Platform must be enabled. Open Turn Windows Features on or off and ensure ‘Virtual Machine Platform’ is checked.
  • Hardware virtualization capabilities must be enabled in BIOS. Check with your system manufacturer for details.
  • You must have admin privileges to install WSL. Standard user accounts cannot install WSL.
  • Your system should have at least 4GB of RAM for optimal WSL performance. 8GB or more is recommended.

Once your system meets the requirements, you’re ready to install WSL!

Install the Linux Kernel Update Package

The first step is to install the latest Linux kernel update package from Microsoft. This provides the Linux kernel within Windows that will allow Linux distributions to run.

To install the update package:

  1. Open Settings and go to Windows Update.
  2. Click on Check for Updates. Install any available updates.
  3. Once updates are installed, search for “Linux kernel update package” and install it.
  4. Restart your system after the kernel update is installed.

The kernel update package is crucial for running WSL and Linux distros fast and smoothly on Windows 11.

Enable the Virtual Machine Platform (Optional)

The Virtual Machine Platform feature is required for WSL. It should be enabled automatically when installing the Linux kernel update, but you can verify by following these steps:

  1. Open Turn Windows features on or off.
  2. Check that ‘Virtual Machine Platform’ is enabled. If not, enable it.
  3. Click OK and restart if prompted.

With the Virtual Machine Platform enabled, your system is now ready for installing Linux distros using WSL.

Install Your Linux Distribution of Choice

Now comes the fun part – picking your preferred Linux distribution to install via the Microsoft Store! The main options include:

  • Ubuntu – The most popular Linux distro overall. Ubuntu offers a great starting point for Linux beginners.
  • Debian – Debian is the base for many other Linux distros, including Ubuntu. It’s stable and lightweight.
  • Kali Linux – A distro focused on security, penetration testing, and ethical hacking.
  • Fedora Remix – A version of Fedora optimized for WSL usage. It’s powerful but easy to use.
  • Pengwin – A WSL-focused distro based on Debian that claims faster I/O speeds.
  • Alpine WSL – Very compact distro good for smaller footprint deployments in WSL.

I recommend Ubuntu or Debian for beginners. But feel free to install multiple distros and test them out!

To install your chosen Linux distro:

  1. Open the Microsoft Store app on your Windows 11 system.
  2. Search for the name of the Linux distro you want to install.
  3. Select your distro from the search results and click Get to install it.

The Linux distro will download and install automatically, like any other app. Easy!

Set Up a Linux User Account

Once the Linux distro finishes installing from the Microsoft Store, you must create a user account within the Linux environment.

The first time you launch the distro, it will prompt you to create a new user account and password. This account is separate from your Windows user account.

Make sure to pick a memorable username and a strong password. This account will be used to log in and operate within the Linux environment.

The account you set up will be an administrator account within the Linux distro with sudo privileges.

Install a Linux Terminal Emulator

Now that you have WSL installed and configured, you need an interface to interact with it. The main options for accessing WSL include:

  • Windows Terminal – Install from the Microsoft Store. The recommended terminal for WSL as it’s designed for it.
  • Command Prompt – The traditional Windows command line tool. It works with WSL but has limited functionality.
  • PowerShell – Includes some WSL integration but not as feature-rich as Windows Terminal.

I suggest installing the Windows Terminal from the Microsoft Store for the best experience. Once installed, you can launch it and access your Linux distros from the dropdown menu.

See also  Simple Tasks in Windows 11 vs macOS Sonoma

Windows Terminal provides useful features like multiple tabs, themes, customization, split panes, and more that optimize the WSL experience.

Initialize the Linux Environment

When you launch your Linux distro, it will need to initialize, which sets up your Linux filesystem and performs some first-time setup operations.

Initialization only happens on the first launch. Click the ‘Initialize now’ button when prompted to initialize your Linux environment.

The initialization performs the following:

  • Set up your Linux user account and password
  • Generates SSH keys for your Linux user
  • Installs your default shell environment
  • Populates the filesystem from your distro’s root image
  • Sets up the environment based on your distro’s package manager

Be patient, as the initialization can take a couple of minutes. The time varies based on the distro’s root filesystem image size.

Once finished, you’ll be logged into your Linux environment in the terminal!

Explore Linux Basics

Now that you’re up and running with WSL, I recommend exploring Linux basics within your distro environment:

  • Try common commands like ls, cd, mkdir, touch To navigate directories and create files.
  • Install packages using your distro’s package manager, like apt or pacman.
  • Change directories using full paths like cd /usr/local/bin or relative paths like cd ../../.
  • Use text editors like nano, vim or emacs to create and edit files.
  • cat or less files to output their contents to the terminal.
  • export/unset environment variables and use echo $VAR to print values.
  • Use sudo to run commands with superuser privileges.

Take time to practice Linux CLI basics before moving on to more advanced WSL functionality.

Install Windows Terminal Themes and Settings

While the defaults are functional, I recommend customizing Windows Terminal to suit your preferences. Here are some quick ways to improve the aesthetics and usability:

  • Themes – Open settings and change the default profile’s color scheme with many options available.
  • Font – Change the font face and size like Consolas at 14pt for better readability.
  • Acrylic Effect – Toggles background acrylic effect to make the terminal translucent.
  • Tabs – Set your preferred tab-switching shortcuts like Ctrl+Shift+T.
  • Scrollback – Increase scrollback lines to review more terminal output history.

Take time to play with various customizations – settings like padding, cursor shape, quake mode, and more. You can also create multiple profiles for different themes or Linux distros.

These customizations will help you be more productive within Windows Terminal.

Troubleshooting Tips

In some cases, you may run into issues installing or running WSL. Here are solutions to common problems:

  • Installation failures – Ensure Virtualization is enabled in BIOS. Some systems require you to enable Intel VT-x or AMD-V virtualization extensions.
  • Permissions errors – Try reinstalling or resetting your Linux distro. Make sure to initialize as a non-root user after installation.
  • Program not found – If commands like python or git return errors, and install them properly within your Linux distro. Do not try to invoke Linux programs from Windows.
  • Network or internet access issues – Check that the Windows firewall is not blocking access to WSL. You can add an exception for WSL access if needed.
  • High CPU or RAM usage – Close background Windows apps and processes to free up system resources for WSL VM. Upgrade RAM if needed.
  • Slow disk performance – Use an SSD rather than an HDD. WSL relies heavily on fast disk speeds.

Hopefully, these tips will help troubleshoot any issues that arise with using WSL on Windows 11!

Tips for Improving WSL Performance

To get the best possible performance out of WSL, I recommend these tips:

  • Place your Linux distro root file system directory on an SSD drive for faster read/write speeds.
  • Use a lightweight window manager within your Linux distro like Xfce or LXDE rather than resource-heavy ones like Gnome or KDE.
  • Disable GUI animations and visual effects in your Linux desktop environment.
  • Don’t install bloated IDEs; stick to lightweight editors like Vim, Nano, or VS Code.
  • Shut down background processes and services not being used in your Linux environment.
  • Set CPU and memory limits on the WSL 2 VM via the wsl.conf file.
  • Enable the ptrace setting and increase the vCPU count for the WSL 2 VM.
  • Use Windows Terminal for interacting with WSL rather than GUI apps or other terminals.
  • Run intensive Linux apps that don’t require GUI within WSL rather than using the Linux GUI desktop.

These tips will help you optimize Windows and WSL for maximum speed and performance.

Advanced Guide for Optimizing WSL

Beyond the basics, you can take several advanced steps to optimize and customize your WSL setup. Here’s an advanced guide on things you can tweak:

Utilize the .wslconfig file

The .wslconfig file gives granular control over WSL settings and parameters. With it you can configure:

  • Custom Linux distro root directory path
  • Initial distro to load on start
  • Resources limits like memory and CPU
  • ptrace settings for Docker compatibility
  • Windows to Linux interop settings

See Microsoft’s documentation for details on the wide array of .wslconfig options.

Adjust Virtual Machine Configuration

You can modify settings for the underlying Hyper-V VM used by WSL 2 for improved performance:

  • Increase number of vCPUs
  • Raise memory allocation
  • Enable nested virtualization
  • Adjust swap file size on Linux drive
  • Disable dynamic memory for static allocation

Use Hyper-V Manager or bcdedit command to tweak advanced VM parameters.

Move Pagefile and Swap to Fast Drive

Place the Windows pagefile and Linux swap file on fast SSD storage rather than the OS drive:

  • Pagefile on Windows should be on fastest NVMe or SSD drive
  • Linux swap should reside on WSL root filesystem (often a separate drive)
  • Ensure swap size is 2x RAM for best performance
See also  How to Connect HDMI Laptop to DisplayPort Monitor

This provides maximum speed for memory paging and swapping.

Install a Custom Linux Kernel

The default Linux kernel used in WSL 2 can be replaced with a custom optimized kernel:

  • Benefits include latest kernel features, security updates and optimizations
  • Can enable additional functionality like systemd integration
  • Distro maintainers offer special WSL kernels

Downside is losing automatic kernel updates from Microsoft.

Consider Third Party Tools

Utilities like WSL2 Docker Desktop Integration and WSL Reverse Integration simplify using Docker and running Windows apps in WSL.

Third-party tools can further enhance WSL usability, compatibility, and features.

By applying these advanced steps, you can truly maximize the utility and performance of the Windows Subsystem for Linux. WSL is an incredibly powerful tool when configured properly.

Graphical Program Options for WSL

Working directly in the Linux terminal is fine for many tasks. But sometimes, you’ll want to run GUI desktop apps or editors. Here are your options:

  • X Server – Install an X server like XMing or VcXsrv on Windows. Sets up an X11 server to display Linux GUI apps.
  • Desktop Environment – Install a Linux desktop environment like KDE, Gnome, or Xfce within WSL to get a full Linux GUI.
  • Remote Desktop – Use XRDP or VNC to remotely connect to your WSL desktop GUI from Windows.
  • Individual Apps – Some Linux GUI apps like GIMP can install Windows versions that integrate better than using X-Forwarding.

For native Linux GUI apps, an X server is easiest. For a full desktop environment, install it within WSL and use remote desktop. Individual apps it depends on your use case.

Test different methods to find which graphical program workflow is right for you.

Using the Linux Filesystem from Windows

Windows and Linux have separate but interconnected filesystems when using WSL. By default, Windows can access the Linux root filesystem under:

\\wsl$

Likewise, Linux can access the Windows C drive and other drives mounted under:

/mnt/c 
/mnt/d
etc.

This makes it easy to:

  • Open Linux files in Windows apps
  • Build Windows/Linux hybrid projects
  • Share files across OSes

Some tips:

  • Use /usr/local rather than Program Files for cross-OS packages
  • Store Linux config files under /etc/ rather than Windows
  • Prefix Windows paths with /mnt/c when accessing from Linux

The interop between Windows and Linux filesystems is a major WSL advantage.

WSL System Administration and Management

Managing Windows Subsystem for Linux involves many of the usual Linux admin tasks:

  • User accounts – Manage users and groups using useradd, usermod, etc. Set password policies.
  • Software updates – Regularly update packages via apt, pacman, etc. Enable auto-updates for security.
  • Resource monitoring – Check CPU, memory, disk usage with top, df, du and other tools.
  • Background services – Control which daemons and services run at startup with systemctl.
  • Log files – Monitor log files in /var/log/ and configure logging with rsyslog.
  • Network and firewall – Configure network settings using nmcli or netplan. Adjust firewall with iptables or ufw.
  • Remote access – Set up SSH keys for passwordless remote login. Consider two-factor authentication.

Apply standard Linux best practices for hardening, automation, and configuration management.

Development Environment Options

One of the most popular uses of WSL is setting up a Linux development environment on Windows. WSL works great for these languages and frameworks:

  • Node.js – Install Node via nvm and leverage npm for modules. Develop/test apps locally before deploying.
  • Python – Take advantage of Python on Linux for frameworks like Django and Flask.
  • Ruby on Rails – Install Ruby Version Manager and Rails for full-stack development.
  • Go – Use Go tooling like golangci-lint for building Windows/Linux Go programs.
  • Rust – Compile Rust into native Windows executables right from WSL.
  • PHP – Run LAMP or LEMP stack natively within WSL.
  • Docker – Manage Docker containers seamlessly within WSL using Docker Desktop integration.

WSL unlocks the Linux ecosystem for developers on Windows. You get native-speed tooling and ecosystem for many languages/frameworks.

GUI Application Options

Earlier we covered accessing GUI apps from Windows using X Server or Remote Desktop. But you can also run GUI apps entirely within WSL using a Linux desktop environment.

Some options include:

Xfce

A lightweight desktop environment. Install with:

sudo apt install xfce4

Launch with startxfce4 and access via remote desktop.

KDE Plasma

A fully featured desktop with customization options:

sudo apt install kde-plasma-desktop

Gnome Flashback

Leaner version of Gnome that uses less resources:

sudo apt install gnome-flashback

LXQt

Very lightweight Qt-based environment:

sudo apt install lxqt

I recommend Xfce or LXQt for getting started with GUI apps in WSL. Heavier desktops like Gnome and KDE may impact performance.

Sharing Network Resources Between Windows and WSL

Windows and WSL can share networking resources like:

  • Networks
  • Ports
  • Hostnames
  • Proxy settings

This enables transparent communication between Windows and Linux apps running via WSL.

To enable resource sharing:

  1. Open Windows Settings
  2. Select Network & Internet -> Properties
  3. Under Remote Port Type, choose Allow connections from any version of Windows

Now Windows firewall rules will apply to WSL processes and apps.

You can also access Windows hostnames from Linux using .exe suffix, like MyPC.local.exe

And Windows can access Linux hostnames using .wsl suffix.

Configuration is automatic in most cases but these tips can resolve issues accessing networking resources across OSes.

See also  Diffusion Toolkit: Organize Your AI Images by Prompt

Tips for Running Linux GUI Apps

Linux GUI apps can be run from within WSL using a couple different methods:

  • X Server – Install XMing or VcXsrv on Windows to display Linux app GUIs. Set DISPLAY variable.
  • Remote Desktop – Install a Linux desktop environment in WSL and remote connect from Windows.
  • Wayland – Experimental support for running Wayland apps natively under WSL

Here is the continuation of the article:

Some tips when running Linux GUI apps:

  • With X Server, allow connections from “Any Address” in your X Server config to permit WSL access.
  • For Remote Desktop, secure connections using SSH rather than VNC for security.
  • Wayland support is still early but shows promise for better integrated Linux GUIs.
  • Don’t expect GPU acceleration for Linux apps under WSL – the VM architecture doesn’t provide direct GPU access.
  • You may need to tweak your Linux user’s .Xauthority file for display access when using X Server.
  • For max performance, use GUI apps sparingly and only when necessary within WSL.
  • Individual Linux apps like GIMP can run faster by installing Windows native versions.

With some configuration, you can get GUI apps working smoothly. But overall, sticking to CLI apps within WSL will provide the best experience.

WSL Filesystem Performance Tips

The WSL filesystem resides within a VHDX virtual disk giving Linux its own partitions and devices.

For best filesystem performance within WSL:

  • Place the VHDX disk on fast SSD storage, preferably an NVMe drive.
  • At install time, pick ext4 rather than ext3 for support for modern features.
  • Keep the WSL VHDX disk lean and remove unneeded files/packages.
  • Perform periodic maintenance like apt autoremove and fsck on Linux drives.
  • Add a /home partition if storing lots of user files to avoid filling /.
  • Benchmark read/write speeds with dd and hdparm to verify performance.
  • Enable write caching on the VHDX with Enable-WindowsOptionalFeature -FeatureName Microsoft-Windows-Subsystem-Linux -Online -NoRestart
  • Compress rarely accessed WSL files using gzip to optimize disk usage.

You can achieve excellent filesystem performance by following these steps. The key is running WSL on an SSD.

Supporting Systemd for Improved Compatibility

By default, WSL 2 uses a simplified init system rather than the full systemd. But you can enable full systemd support by:

  1. Installing a custom Linux kernel containing the systemd patches
  2. Configuring the systemd option in .wslconfig:
[boot]
systemd=true
  1. Rebuilding systemd within your WSL distro if necessary

Benefits include:

  • Better application and distro compatibility
  • Additional systemd services for logging, power management, etc.
  • Consistent experience with real Linux environment

The main downside is added complexity and resources needed to run full systemd.

But for advanced users, upgrading to systemd can improve interoperability and compatibility when running complex apps within WSL.

Leveraging WSL 2’s VM Architecture

WSL 2 runs Linux distros within lightweight virtual machines based on Hyper-V.

This VM architecture provides advantages:

  • Better isolation between host and guest compared to WSL 1
  • Runs actual Linux kernel rather than emulating kernel calls
  • Decoupled lifecycles between Windows host and Linux guest OSes
  • Flexibility to operate WSL machines independently of host
  • Ability to leverage hypervisor features like VM snapshots

You can interact with the underlying VM using commands like:

wsl.exe -l -v
wsl --list --verbose

And tools like Hyper-V Manager for advanced configuration not exposed within WSL itself.

For example, adjusting VM resources or sharing folders outside the normal \\wsl$ paths.

The VM model makes WSL 2 incredibly flexible and performant.

Integrating Windows and Linux Workflows

A key benefit of WSL is combining Windows and Linux tools into unified workflows:

  • Filesystems exposed via \wsl$\ paths make sharing data seamless
  • Editors like VSCode work on Windows/Linux projects interchangeably
  • Hybrid languages like Typescript can compile across platforms
  • Docker Desktop with WSL integration manages containers in Linux VM
  • Windows Terminal provides tabbed access to traditional CMD/PS and Linux shells
  • Visual Studio solutions can include .NET code executing in WSL

To integrate workflows:

  • Configure Windows Terminal as the default terminal for WSL rather than distro defaults.
  • Share source code across Windows/Linux filesystems rather than duplicating.
  • Use cross-platform tools like Visual Studio Code as the IDE for unified dev experience.
  • Don’t mix platform-specific tools like Windows grep and Linux grep – stick to one.
  • Abstract filesystem paths in scripts using variables like $PROJECTS_DIR to allow portable code.

With some care, you can blend the best Windows and Linux worlds using WSL.

WSL 2 Tips and Tricks

Here are some additional tips for working with WSL 2:

  • Shut down WSL 2 distros cleanly with wsl --shutdown to avoid corruption.
  • Access Windows drives from /mnt/ paths. Like /mnt/c maps to C: drive.
  • Launch Windows apps from Linux with /mnt/c/Windows/System32/Notepad.exe
  • Import Linux shell scripts into Windows Powershell with . foo.sh
  • Windows path translation with wslpath 'C:\Path\file'
  • Distro management with wsl --list, wsl --unregister
  • Change default distro with .wslconfig or wsl -s
  • Faster boot by removing swapfile after install with sudo swapoff -a
  • Install additional DEs like KDE Plasma without impacting main distro.

Take advantage of these tips to simplify working across environments with WSL 2.

Conclusion

This comprehensive guide covered the full process of installing and configuring WSL 2 on Windows 11. Here are some key takeaways:

  • Enable required features like Virtual Machine Platform and install the Linux kernel update package.
  • Choose a Linux distro from the Microsoft Store and set up your user account when initializing.
  • For terminal access, use Windows Terminal for the best experience.
  • Customize WSL and Windows Terminal to suit your workflow and productivity.
  • Optimize performance through .wslconfig tweaks, resource allocation, and disk optimizations.
  • Access Linux files from Windows and vice versa for unified dev workflows.
  • Manage WSL through Windows admin center integration and Hyper-V Manager.
  • Take advantage of WSL 2’s lightweight VM architecture for Linux flexibility on Windows.

With WSL, you truly get the best of Windows and Linux blended into one seamless experience. I hope this guide helps you maximize the capabilities of the Windows Subsystem for Linux!

References

  1. Install Windows Subsystem for Linux (WSL) on Windows 11. Microsoft. https://docs.microsoft.com/en-us/windows/wsl/install
  2. Windows Subsystem for Linux Guidance for WSL Users. Microsoft. https://docs.microsoft.com/en-us/windows/wsl/basic-commands
  3. Windows 10 tip: The best way to use WSL 2. Ed Bott. ZDNet. https://www.zdnet.com/article/windows-10-tip-the-best-way-to-use-wsl-2/
  4. The non-beginner’s guide to optimizing WSL2 for peak performance. Nick Janetakis. https://nickjanetakis.com/blog/the-non-beginner-guide-to-optimizing-wsl-2-for-peak-performance
  5. WSL 2 Best Practices. Samuel Karp. https://devblogs.microsoft.com/commandline/wsl-2-best-practices/
  6. How to Install and Use Linux GUI Apps on Windows Subsystem for Linux. Beebom. https://beebom.com/how-install-linux-gui-apps-windows-subsystem-linux/
5/5 - (2 votes)

Mohamed SAKHRI

I am Mohamed SAKHRI, the creator and editor-in-chief of Tech To Geek, where I've demonstrated my passion for technology through extensive blogging. My expertise spans various operating systems, including Windows, Linux, macOS, and Android, with a focus on providing practical and valuable guides. Additionally, I delve into WordPress-related subjects. You can find more about me on my Linkedin!, Twitter!, Reddit

Leave a Comment