Windows Subsystem for Linux (WSL) is a feature of Windows 10 and later that allows you to run a Linux environment directly on Windows without the need for a virtual machine. It’s perfect for developers, and those who want to leverage a Unix-based development environment on Windows. Here’s how you can get started with WSL.
Step 1: Enable WSL
Windows 10
-
Open PowerShell as Administrator:
- Press
Win + X
to open the Power User menu. - Select "Windows PowerShell (Admin)".
- Press
-
Enable WSL:
- Type the following command and press Enter:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
- Type the following command and press Enter:
-
Enable Virtual Machine Platform:
- Type the following command and press Enter:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
- Type the following command and press Enter:
- Restart Your Computer.
Windows 11
-
Open Settings:
- Press
Win + I
to open Settings.
- Press
-
Access the Apps Menu:
- Navigate to "Apps" > "Optional features".
- Under "Related settings", click on "More Windows features".
- Enable WSL:
- Check "Windows Subsystem for Linux" and "Virtual Machine Platform".
- Click "OK" and restart if prompted.
Step 2: Install a Linux Distribution
-
Open Microsoft Store:
- Search for "Microsoft Store" in the Start menu.
-
Choose a Linux Distribution:
- Search for "Linux" and select your preferred Linux distribution, such as Ubuntu, Debian, or Kali.
- Install the Distribution:
- Click "Get" or "Install" to begin downloading and installing the distribution.
- Once installed, click "Launch" to initialize your Linux environment.
Step 3: Set Up Your Linux Environment
-
Create a User Account:
- When you first launch the distribution, you’ll be prompted to create a user account and password.
-
Update Package Lists:
- Open your Linux terminal and enter the following command to update your package lists:
sudo apt update
- Open your Linux terminal and enter the following command to update your package lists:
- Upgrade Packages:
- To upgrade installed packages to the latest version, use:
sudo apt upgrade
- To upgrade installed packages to the latest version, use:
Step 4: Start Using WSL
-
Access WSL:
- You can launch your installed Linux distribution from the Start menu or by typing its name into the Windows Terminal.
-
Install Additional Software:
- To install software, use the package manager provided by your distribution (e.g.,
apt
for Ubuntu):sudo apt install <package_name>
- To install software, use the package manager provided by your distribution (e.g.,
-
Interoperability with Windows:
- Access your Windows files from within your Linux environment at
/mnt/c/
and use Linux commands to navigate and manage them.
- Access your Windows files from within your Linux environment at
- Switch Between Versions:
- To switch to WSL 2, if desired, use the command:
wsl --set-version <distro_name> 2
- To switch to WSL 2, if desired, use the command:
Step 5: Further Configuration (Optional)
- Customize Your Shell: Install tools like Zsh or customize your Bash prompt for a better experience.
- Shared Environment: Set up shared environment variables and configurations between Windows and Linux.
- Explore Development Tools: Install development tools and editors like Visual Studio Code for seamless integration with WSL.
Troubleshooting
- Verify Installation:
- Check the WSL version with:
wsl -l -v
- Check the WSL version with:
- Update WSL:
- Make sure you have the latest WSL update:
- Check for updates via Windows Update or use the latest Windows Insider build.
By following these steps, you should have a fully functional Linux environment on your Windows machine, ready for development or exploration of Linux-based tools and commands. Enjoy!