Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: June 26, 2024
Windows Subsystem for Linux (WSL) is a compatibility layer that enables users to run Linux binary executables natively on the Windows operating system. Initially released in 2016, WSL provides us with a powerful Linux environment within Windows, allowing us to run Linux command-line tools, utilities, and programs straight from our Windows PC. This seamless connectivity streamlines the workflow for developers who work in both Windows and Linux systems.
In this tutorial, we’ll look at the fundamentals of WSL, including installation, functionality, and usage.
Windows Subsystem for Linux (WSL) is simply a Windows feature that allows you to install a whole Linux distribution on your Windows PC. It connects Windows and Linux by delivering a complete Linux kernel and user space under Windows. WSL comes in two versions:
Additionally, WSL provides a seamless experience by combining the capability of Linux and the comfort of Windows.
Most developers use WSL primarily for the benefits it provides. Some of the most notable benefits includes:
Furthermore, WSL has the advantage of not requiring a dual-boot system or separate hardware to run Linux, saving both time and resources.
To get started with using a Linux environment on our Windows machine, we can install WSL in a few basic steps.
First, on Windows, let’s enable the WSL feature. We’ll do this by launching PowerShell as an administrator and executing the wsl command:
$ wsl --install
Furthermore, this command enables WSL capability and installs the default Linux distribution, which is normally Ubuntu.
WSL 2 provides considerable performance gains and full system call compatibility. Let’s make WSL 2 the default version by running another PowerShell command:
$ wsl --set-default-version 2
Additionally, this ensures that any new Linux distribution installed uses WSL 2 by default.
We can install more Linux distributions from the Microsoft Store. For example, to install Ubuntu, we can launch the Microsoft Store, search for Ubuntu, choose our preferred Ubuntu version, and click Install.
Thereafter, we can run Ubuntu to complete the setup and create a new user account.
We can also use PowerShell to ensure that WSL is correctly installed and to examine the installed distributions:
$ wsl --list --verbose
Moreover, this will show a list of all installed distributions, along with respective WSL versions.
Now that WSL and a Linux distribution have been installed, let’s see how to carry out some simple activities in WSL.
After installing Ubuntu, we can launch it by entering Ubuntu into the Windows search box. This will open a terminal window from where we can execute Linux commands:
$ pwd
/home/baeldung
$ echo "Hello, Baeldung! welcome to WSL"
Hello, Baeldung! welcome to WSL
Additionally, WSL offers us that native Linux terminal experience.
WSL enables us to access Windows files directly from the Linux environment. Windows drives are mounted under the /mnt directory:
$ cd /mnt/c
$ ls
The cd command navigates to the C: disk, while the ls command displays its contents.
One of WSL’s most powerful characteristics is its ease of use with Windows and Linux systems.
Additionally, we can easily run Windows executables directly from WSL. For instance, to launch Notepad from WSL:
$ notepad.exe
This command would launch the Notepad application.
Finally, we can call Linux binaries from Windows Command Prompt or PowerShell, thereby improving communication between the two platforms.
While WSL provides various benefits, there are also some limitations that we should be aware of.
WSL has less access to hardware resources than a full Linux installation. For example, GPU access is limited, although WSL 2 has made progress in this area by supporting GPU acceleration in select cases.
Some Linux apps may not function properly under WSL because of differences in the underlying architecture.
Furthermore, although WSL 2 has substantially improved compatibility, it’s not necessarily an ideal replacement for a full Linux environment.
WSL 2 operates in a virtualized environment, which can occasionally cause network configuration complications, particularly when working with port forwarding and network interfaces.
Additionally, several networking functions seen on native Linux systems may not work properly within WSL.
Windows Subsystem for Linux (WSL) bridges the gap between the Windows and Linux environments, giving developers a strong tool for working with both operating systems.
In this article, we looked at the fundamentals of WSL, including installation, functionality, and usage.
Finally, WSL increases productivity and simplifies workflow by allowing Linux command-line tools and software to be used directly on Windows, making it a useful tool for developers and IT professionals.