How to Install a Linux Distribution on Windows 10/11 with WSL & WSL2
Guide Installation Linux Windows WSL WSL2Hi all, welcome to MusaBase! In this step-by-step guide, we will learn how to install and configure a full Linux Distribution on Windows 10/11 using WSL or WSL2.By following these instructions, we will enjoy seamless Linux GUI applications on Windows, and the ability to run our favorite tools side-by-side with our Windows desktop.
Jump To:
What is WSL/WSL2?
The Windows Subsystem for Linux (WSL) allows us to run a complete Linux distribution alongside Windows without a resource-heavy VM.WSL 2 boosts performance and compatibility by using a real Linux Kernel inside a lightweight VM. WSL2 is available on Windows 10 (version 2004, build 19041 or later) and Windows 11. Installing Windows 11 is nearly identical and benefits from tighter OS integration.
Prerequisites
- Processor: Intel or AMD 64-bit compatiable and must support virtualizaiton. and also the Hardware-Assisted Virutalization or Intel VT-x or AMD-V should be enabled in your BIOS/UEFI.
- RAM: 8GB to 32GB (the more ram the better).
- Storage: WSL2 itself need around 5GB, though each Linux distro will need additional space.
- Windows Version:
- Windows 10: Version 2004 (build 19041 or later) for WSL2 (older versions can run only WSL 1 or require manual installation).
- Windows 11: Any edition.
Step 1. Enable Windows Features for WSL & WSL2
WSL 2 requires two Windows features on Windows 10/11:
- Windows Subsystem for Linux
- Virtual Machine Platform
We can enable these two features either through:
- GUI (Graphical)
- PowerShell (Admin)
1.1. Enable via GUI
- Press the Windows key or open start-menu and type "Turn Windows features on or off" and open it.
- In the Windows Features dialog, check:
- Virtual Machine Platform
- Windows Subsystem for Linux
1.2. Enable via PowerShell (Admin)
- Press Windows key or open start menu and type in the search box PowerShell, then right-click and select Run as Administrator.
- In the elevated console, run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Once the features are enabled (via GUI or PowerShell), restart the PC to complete the installtion.
Step 2. Install WSL & WSL2 on Windows 10/11
If you`re running a supported Windows 10 build (2004, Build 19041 or later) or Windows 11, Microsoft provides a single command to install WSL end-to-end.
- Open PowerShell as an administrator.
- Run the command:
wsl --install
When we run wsl --install, it will:
- Automatically enable any missing WSL components.
- Download and install the latest Linux Kernel.
- Configure WSL2 as the default version.
- Download and install the default Linux distribution typically Ubuntu.
- After the installation finishes, restart PC to apply all changes.
Step 3. Launch Linux Shell with WSL
With the minimal Ubuntu installation complete, let`s launch our new Linux environment.
- Open PowerShell as an administrator
- Run the command:
wsl
After running the command the WSL system will ask you to set a Username and Password enter these and it will log you into your Ubuntu Linux System.
Now, we can launch any Linux application in Windows via WSL terminal or from the Start menu. Any application we install in Ubuntu will appear there, ready to launch with a single clic.
A simple demonstration:
I`m going to run Krita, a powerful digital painting application originally designed for Linux.
Keep in mind this is a bare-minimal Linux System, which initially provides only command-line interface (CLI).
Step 4. Implementing GUI for WSL
Now, even though WSL (and WSL2) lets us run Linux and its apps on Windows, it`s fundamentally designedas command-line interface (CLI). That means we can only interact via commands. However, we can still install and run a full Linux desktop environment ( for this guide, "Ubuntu") using one of two methods.
- X Server method
- Remote Desktop Protocol (RDP) method
4.1. X Server Method
X Server (Xorg) is the display server that provides a graphical interface for Linux applications. It bridges hardware and graphics software, letting GUI apps render on our Windows screen and accpet keyboard/mouse input.
4.1.1. Download X Server
- Download VcXsrv (X Server for Windows) from SourceForge link.
- Install it.
- URL of VcXsrv:
https://sourceforge.net/projects/vcxsrv/
Now that Ubuntu is installed under WSL, open the Ubuntu terminal from the start menu by typing "Terminal" in the search box.
- By default we`ll get PowerShell, we can swithc to Ubuntu by selecting if from the dropdown menu in the terminal`s top left corner.
4.1.2. Update, Hold & Upgrade Packages
- In the Ubuntu terminal, run these commands consecutively:
sudo apt update
sudo apt-mark hold acpid
sudo apt upgrade
- sudo apt-mark hold acpid: Tells APT to lock acpid at its current version so that it won`t be upgraded, removed, or newly installed by any subsequent apt upgradeor dependency operation.
- The acpid package provides ACPI event handling such as power-button, battery events on Linux, but WSL2 doesn`t support ACPI hardware events, becuase we are in a virtual machine. When acpid is installed or upgraded inside a WSL2 distro, it fails to bind to ACPI sockets, flooding systemd with errors and crashing services or desktop session. Marking acpid on hold prevents its insatlling or upgrade, that`s why marking acpid on hold helps avoiding these limitless error loops and make a stable desktop environment on an XServer under WSL2.
4.1.3. Install Ubuntu-Desktop & Gnome
- In the terminal, run:
sudo apt install ubuntu-desktop gnome
We can install any supported desktop enviornment such as KDE Plasma, Mate, etc. But in this article GNOME Desktop Session on XServer makes more sense, because its native to Ubuntu.
Note: If you already have systemd enabled (systemd=true) in your /etc/wsl.conf file then skip next two (4.1.4 and 4.1.5) step.
4.1.4. Enable Systemd
Ensure systemd is enabled (systemd=true) in wsl.conf file.
- In Ubuntu terminal run:
sudo nano /etc/wsl.conf
- If systemd=true isn`t present, add the line under [boot], then press Ctrl + O to save and Ctrl + X to exit.
- Please, see the images for better clearification:
4.1.5. Update WSL
- In the Ubuntu terminal, type exit to close WSL session.
- In Window`s PowerShell run these two commands consecutively:
wsl --shutdown
wsl --update
- wsl --shutdown: Will close any running WSL instances.
- wsl --update: Will update Linux to its latest kernel if any available.
4.1.6. Define environment variables
- Reopen Ubuntu terminal.
- Next, run:
sudo nano ~/.bashrc
- In the bashrc file navigate to the bottom with down () arrow keys and add the environment variables, then press Ctrl + O to save and Ctrl + X to exit:
export DISPLAY="$(ip route | awk '{print $3; exit}')":0;
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
export XDG_SESSION_DESKTOP=ubuntu
export XDG_SESSION_TYPE=x11
export XDG_CURRENT_DESKTOP=ubuntu:GNOME
export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share/:/var/lib/snapd/desktop
export GNOME_SHELL_SESSION_MODE=ubuntu
export XDG_RUNTIME_DIR="/run/user/1000"
Each of these environment variables helps GUI application and desktop-integration tools locate configuration, data and decide how to start and render your session.
- DISPLAY: Specifies the XServer address and screen number to use format hostname:display.screen.
- XDG_CONFIG_HOME: Base directory for user-specific configuration file to ~/.config.
- XDG_DATA_DIRS: Colon-separated list of system-wide config directories to search after XDG_CONIFG_HOME.
- XDG_SESSION_DESKTOP: Short identifier for the desktop session sucha as ubuntu, plasma, used by logind and session managers.
- XDG_SESSION_TYPE: Indicates the session transport/protocol one of x11, wayland, etc, used by systemd-logind and related tools.
- XDG_CURRENT_DESKTOP: Desktop environment identifiers such as ubuntu:GNOME, KDE, etc. Used by xdg-utils and portals for theming and applications integration.
- XDG_SESSION_CLASS: Specifies the session`s class such as users, greeter, detemining how systemd-logind manages your session.
- XDG_RUNTIME_DIR: List of base directories for system-wide data files (icons, desktop entries, etc. Defaulting to /usr/local/share/:/usershare.
- GNOME_SHELL_SESSION_MODE: Sets GNOME Shell`s session mode (e,g, ubuntu, classic), overriding the --mode flag and selecting which GNOME extensions and panels to load.
- XDG_RUNTIME_DIR: Points to a user-specific runtime directory (usually /run/user/$UID), used for sockets, PID files, and other pre-session transient data.
- Next, in the terminal run these commands consecutively:
sudo mkdir -p /run/user/1000
sudo chmod 700 /run/user/1000
sudo chmod $(whoami): /run/user/1000
These three commands ensure that XDG runtime directory (/run/user/1000) exits, is owned by our user, and has secure permissions so that user-specific runtime files like D-Bus sockets can be created and accessed by desktop services.
Without this directory properly set up, GUI applications and user services relying on $XDG_RUNTIME_DIR will fail to start or communicate.
4.1.7. Launch X Server
Now laiunch VcXsrv (X Server) that we installed earlier.
- Open the Start menu, type xlaunch, and run the application.
- On "Select display settings" screen, choose "One large window" or "Fullscreen" based on your needs and click .
- On "Select how to start clients" screen, choose "Start no client" and Click .
- On "Extra settings" screen, tick all check boxes and add one parameter in Additional parameters for VcXsrv at the bottom and click :
-dpms
- On the final screen, click . VcXsrv will start, but we might see a black window until we launch our desktop session.
4.1.8. Launch Desktop Session
- Switch back to Ubuntu terminal in WSL.
- Run the following command:
dbus-launch --exit-with-session gnome-session
4.2. Remote Desktop Protocol (RDP) Method
This method is simpler to implement. With RDP, we can use any supported desktop environment without extra configuration.
4.2.1 Install Tasksel
Tasksel is a tools that installas realted group of packages in one go, similar to APT metapackages. It offers a simple interface for tasks like setting up a desktop environment or web server stack.
- First update distro, by running sudo apt update && sudo apt upgrade.
- Then install tasksel and xdrp:
sudo apt install tasksel xrdp
4.2.2. Install an Desktop Enviornment
- In the Ubuntu terminal, run the following command to launch Tasksel interface:
sudo tasksel
- This command will open the following interface, from there we can install any Desktop Environment or Web Server stack
- User keyboard`s Up () and down () arrow keys to navigate thorugh several options.
- Press Space key to select the Desktop Environment you want.
- Press Tab to go to bottom`s option section and choose OK to confirm the download and press Enter to continue.
This time i am choosing KDE Plasma for my Desktop Environment but you can choose any given you want.
4.2.3. Launch Ubuntu desktop session with RDP
- In the terminal run the following command to get the IP for RDP:
ip a
- This command will list network interfaces and their IP addresses.
- Note the eth0: interface`s IPV4 address and copy it.
- Open Start menu and search for RDP or Remote Destkop Protocol in the search box and open it.
- In the RDP window we need to paste the ip address that we just copied and press on connect.
- If all goes well, we`ll see a login prompt. Where we can enter the username and password that we created for Ubuntu under WSL.
Afterwards
WSL is designed primarily for command-line user and development, and while we can run a full desktop evnironment via X Server or RDP, GUI performance can be sluggish and unresponisve. I recommend using a dedicated virtual machine like Oracle Virtual Box or Mircosoft`s Hyper-V, or setting up a traditional dual-boot for full native performance. With that said,
1O1 out! i`ll see you around.
FIN!