Sara loves coding in Linux, but her office computer runs on Windows. Every day, she finds herself switching between her laptop, which runs Linux, and her desktop, which is stuck on Windows. It’s frustrating, inefficient, and feels like she’s living in two different worlds. This is where WSL 2 comes in, bridging the gap between Windows and Linux like never before.
WSL 2 (Windows Subsystem for Linux) is not just a technical upgrade; it’s a game-changer. It brings the best of Linux’s power and flexibility to your Windows machine. With WSL 2, you can run a full Linux kernel, enabling faster file systems, better compatibility, and a seamless development experience. It’s like having a magic portal to Linux right on your Windows desktop.
In this guide, we’ll explore everything you need to know to install and use WSL 2, no matter your technical expertise. Whether you’re a seasoned developer or a curious beginner, this journey will equip you with the tools and knowledge to make the most of WSL 2.
What is WSL 2?
WSL 2 is the second version of the Windows Subsystem for Linux, introduced by Microsoft to make Linux functionality accessible on Windows. Unlike WSL 1, which translated Linux commands into Windows instructions, WSL 2 uses a full Linux kernel. This means it’s faster, more compatible, and better at running Linux software.
If you’ve ever tried to set up a dual-boot system or use a virtual machine to run Linux, you know how complicated and resource-intensive those solutions can be. WSL 2 simplifies this. With just a few clicks, you can have Linux running alongside Windows, sharing files and resources seamlessly. It’s a tool built for developers, but anyone curious about Linux can benefit.
Key Differences Between WSL 1 and WSL 2
-
Performance: WSL 2 uses a full Linux kernel, providing near-native performance.
-
Compatibility: Better support for Linux software, including Docker.
-
File System: Faster file access and better integration with Linux file systems.
-
Network Features: Improved network compatibility and access.
Preparing Your Windows System
Before you get started with installing WSL 2, you need to ensure your Windows system is ready. Think of this as preparing the ground before planting a garden.
Check Your Windows Version: WSL 2 requires Windows 10 version 1903 or later, with Build 18362 or higher. To check your version, press Win + R
, type winver
, and hit Enter. A window will pop up showing your current version.
Update Windows to the Latest Version: Open the Settings app (Win + I
) and navigate to Update & Security > Windows Update
. Click “Check for updates” and install any available updates. Keeping your system updated ensures compatibility and security.
Enable Necessary Features: Open the Control Panel and go to Programs > Turn Windows features on or off
. Enable Windows Subsystem for Linux and Virtual Machine Platform. Click OK, then restart your computer when prompted.
Installing WSL 2 on Your System
Now that your Windows system is ready, it’s time to install WSL 2. Follow these steps carefully, and you’ll have a working Linux environment in no time.
Install WSL: The easiest way to install WSL is by using a single command in PowerShell.
-
Open PowerShell as an administrator. To do this, search for “PowerShell” in the Start menu, right-click on it, and choose “Run as Administrator.”
-
Type the following command and press Enter:
wsl --install
-
This command will: Enable WSL if it’s not already enabled. Set WSL 2 as the default version. Install the default Linux distribution (usually Ubuntu).
The installation may take a few minutes, depending on your system and internet speed.
Restart Your Computer: After the installation, you might be prompted to restart your computer. Make sure to save any open work before restarting.
Set Up Your Linux Distribution: Once your system restarts, the Linux distribution you installed will automatically launch. You’ll see a terminal window asking you to set up a new user account. Follow these steps:
- Enter a username. This can be anything you like but is typically all lowercase.
- Set a password. Make sure to choose something secure but easy for you to remember.
Congratulations! You now have a working Linux environment on your Windows machine.
Choosing a Linux Distribution
While Ubuntu is the default choice for many, WSL supports a variety of Linux distributions. You can explore options like Debian, Fedora, or Kali Linux. To install a different distribution:
- Open the Microsoft Store on your Windows system.
- Search for the desired Linux distribution (e.g., “Debian” or “Fedora”).
- Click Install, and wait for the download to complete.
- Launch the installed distribution from the Start menu and set it up just like Ubuntu.
To see a list of available distributions directly in PowerShell, type:
wsl --list --online
Switching to WSL 2 (If Needed)
If you’ve previously installed WSL but are using version 1, you can switch to WSL 2 with a simple command:
-
Open PowerShell as an administrator.
-
Type the following command to set WSL 2 as the default version for new installations:
wsl --set-default-version 2
-
To upgrade an existing Linux distribution to WSL 2, use this command. Replace
<distribution_name>
with the name of your installed Linux distribution (e.g.,Ubuntu
).wsl --set-version <distribution_name> 2
You can verify which version your distribution is using by typing:
wsl --list --verbose
Customizing Your WSL 2 Environment
Now that you have WSL 2 installed, let’s set it up for optimal use. Think of this step as furnishing a new house—you’re adding the tools and features you need to make it feel like home.
Installing Essential Tools
Linux is known for its flexibility, and WSL 2 lets you tap into that. Here’s how to install some must-have tools and utilities:
Update Package Lists: Start by updating the list of available software packages to ensure you’re installing the latest versions:
sudo apt update
Install Basic Utilities: Add common tools like curl
, wget
, and git
:
sudo apt install -y curl wget git
Programming Languages and Frameworks: Depending on your needs, you can install popular languages and tools. For example:
-
Python:
sudo apt install -y python3 python3-pip
-
Node.js:
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt install -y nodejs
Text Editors: Install lightweight editors like nano
or powerful tools like vim
:
sudo apt install -y nano vim
Accessing Windows Files from Linux
One of the coolest features of WSL 2 is its seamless file integration between Linux and Windows.
Your Windows files are accessible under the /mnt
directory. For example:
- Your
C:
drive is mounted at/mnt/c
. - Your desktop is located at
/mnt/c/Users/<YourUsername>/Desktop
.
You can use Linux commands to manipulate Windows files directly. For example:
ls /mnt/c/Users/<YourUsername>/Documents
Using Windows Programs from Linux
You can also launch Windows programs from WSL 2. For example:
Open Notepad from the Linux terminal:
notepad.exe
Open a file in your default web browser:
explorer.exe .
This integration allows you to combine the best of both operating systems seamlessly.
Running Development Environments in WSL 2
WSL 2 is perfect for development tasks. Let’s look at how you can set up a web development environment.
Installing a Web Server: Run a web server like Nginx or Apache:
For Nginx:
sudo apt install -y nginx sudo service nginx start
Access your server in a browser by visiting http://localhost
.
Working with Databases: Install databases like MySQL or PostgreSQL:
For MySQL:
sudo apt install -y mysql-server sudo service mysql start
Using VS Code with WSL 2: Visual Studio Code has excellent WSL integration:
-
Install VS Code on Windows.
-
Install the Remote - WSL extension in VS Code.
-
Open a folder in WSL directly from VS Code:
code .
Troubleshooting Common Issues
Even the best tools can run into issues. Here’s how to resolve some common problems:
Slow File Performance: WSL 2 is fast, but file operations in /mnt
(Windows-mounted directories) can sometimes feel slower. To speed things up: Work on Linux-native directories (e.g., inside your home directory /home/<username>
).
No Internet in WSL: If you lose internet connectivity in WSL, restarting the WSL service can help:
wsl --shutdown wsl
Installation Errors: If WSL or your distribution doesn’t install properly, check these: Ensure you’ve enabled both Windows Subsystem for Linux and Virtual Machine Platform features. Update your Windows version if necessary.
Conclusion
WSL 2 is more than just a tool; it’s a bridge that brings two powerful worlds together. Whether you’re coding, exploring Linux for the first time, or setting up complex development environments, WSL 2 makes it all easier.