The Windows Subsystem for Linux makes it easy to run a Linux environment on Windows. The integration is so seamless and powerful, that you can even connect VS Code to it and execute code automatically in a Linux terminal. With WSL 2 you no longer need Cygwin or MinGW.
Requirements 📝
To install the Windows Subsystem for Linux (WSL), you must have Windows 10 installed (Build 19041 and higher). WSL 2 also requires you to activate Microsoft Hyper-V. If these two conditions are met, you can proceed.
The following post is based on my video:
Install WSL 2 💾
- Open Windows PowerShell
- Execute
wsl --install
- Verify your installation with
wsl --status
Install Linux 🐧
WSL 2 allows you to install different Linux distributions (Ubuntu, Debian, Alpine Linux & others) from the Microsoft Store. Just open the "Microsoft Store" app and search for your favorite Linux version:
Start Linux on Windows 🏁
Once the Linux installation is complete, you can run it from the Windows Start menu. Here is an example running Ubuntu:
Access Linux Files from Windows 📁
When you start your Linux distribution, all of its files become available in your Windows "Network". Here is how you can see your full Linux filesystem:
- Start Linux (Ubuntu app)
- Open File Explorer ("Win" + "E")
- Enter
\\wsl$
in the address bar
Screenshot:
Access Windows Files from Linux 📁
You can also access your Windows NTFS filesystem from Linux. It works like this:
- Start Linux (Ubuntu app)
- Access your
C:\
drive usingcd /mnt/c
Screenshot:
Connect Visual Studio Code with Linux 🔗
By default, VS Code on Windows uses the Command Prompt when opening a Terminal. However, you can also run your code from your installed Linux environment. Here's how to do it:
- Install the Remote - WSL extension
- Click in the lower left corner of your VS Code and choose "New WSL Window using Distro..."
- A new VS Code window will open and use your Linux terminal by default
Screenshot:
Use Docker with WSL 2 🐳
You don't have to reinstall Docker on your Linux installation. Docker Desktop for Windows allows you to use Docker from your Linux distribution. You just need to select "Enable integration with my default WSL distro" in "Settings" ➝ "Resources" ➝ "WSL Integration".
Screenshot:
Run Linux GUI apps 🎨
If you have Windows 11 (Build 22000 and higher) installed, then you can also run Linux GUI apps from your Windows system.
Closing Note ✍
I hope you are as impressed by the Windows Subsystem for Linux as I am. Please follow me on Twitter or subscribe to my YouTube channel if you liked this post. I would love to hear from you what you are building. 🙂 Best, Benny
Top comments (0)