The Windows Subsystem for Linux (WSL) enables developers to run GNU/Linux environments, including most command-line tools, utilities, and applications, directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.
What is WSL?
WSL provides a lightweight virtual machine environment that hosts a full Linux kernel, allowing you to install and run Linux distributions such as Ubuntu, Debian, Fedora, and more from the Microsoft Store. It integrates seamlessly with Windows file systems and allows for easy interoperability between Windows and Linux tools.
Key Features and Benefits
- Full System Utilities: Access command-line tools like Bash, Git, SSH, apt, yum, and more.
- Application Compatibility: Run Linux applications, including those requiring specific libraries or environments.
- Seamless Integration: Access Windows files from Linux and Linux files from Windows. Run Windows executables from Linux.
- Performance: Offers near-native performance for most command-line operations.
- Easy Installation: Install distributions directly from the Microsoft Store.
Getting Started with WSL
To install WSL, you typically need to enable the feature and then install your preferred Linux distribution. Here's a general overview:
- Open PowerShell as Administrator.
- Run the command:
wsl --install
- This command will enable the necessary features, download the latest Linux kernel, set WSL 2 as the default, and install a default Linux distribution (usually Ubuntu).
- Restart your computer.
- After restarting, the installed Linux distribution will launch and you'll be prompted to create a username and password for your Linux environment.
Common Use Cases
WSL is invaluable for various development workflows:
- Web Development: Run Node.js, Python, Ruby, PHP, and associated tools.
- Containerization: Use Docker Desktop with WSL 2 for a streamlined container experience.
- DevOps: Automate tasks and manage infrastructure using Linux tools.
- Cross-Platform Development: Test and build applications that target both Windows and Linux.
Advanced Configuration
You can configure WSL further, including setting default distributions, managing network settings, and accessing graphical Linux applications with WSLg (available in recent Windows versions). For detailed commands and configuration options, refer to the official Microsoft documentation.
# Example: Running a simple bash script in WSL
echo "Hello from WSL!" > hello.txt
cat hello.txt