How to setup WSL2 and run Linux GUI apps in Windows operating system
Subroto Kumar
Posted on April 1, 2022
Windows Subsystem for Linux (WSL) is a Windows tool that allows developers run a GNU/Linux environment, install packages from the Ubuntu and other Linux archive, and run Linux applications and workflows directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.
Installing WSL2
There are two ways by which we can install wsl2 in windows operating system and this depends on your windows version and build number.
To check your windows version:
Press WIN + R , type winver and then press ENTER .
First Method (Easy Method)
Prerequisites : You must be running Windows 10 version 2004 and higher (Build 19041 and higher) or Windows 11.
1. First we have to open a command prompt with administrator privileges.
Select Start, type PowerShell, right-click Windows PowerShell, and then select Run as administrator.
2. Run this command : wsl --install
This command will enable the required components, download the latest Linux kernal, set WSL 2 as default and install a Ubuntu (by default) distribution.
Only thing your have to do now is to set new Username and Password for your newly installed Ubuntu.
This above command will only works if you are installing WSL for first time and WSL is not installed at your PC at all.
If this method don't work for you then follow the next step.
3. Check the list of available Linux distributins available to download from the online store. To do so, run this command :
wsl --list --online
or wsl -l -o
.
4. Run this command to install your desired Linux Distribution: wsl --install -d <Distribution name>
Here :
<Distribution name>
should be same as one that one mention in NAME section.For example, suppose I want to install Debian then i have to run this command :
wsl --install -d Debian
5. Once the WSL install is completed your will need to set user account and password for your newly install Linux distribution.
Once everything is all done, close the terminal.
To open the installed Linux Distribution:
Select Start, type , and then Select and Run.
Second Method (Manual Method)
This method is more those computer which are running an older build of windows.
Step 1: Open PowerShell as Administrator (Start menu > PowerShell > right-click > Run as Administrator) and run this command :
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
This will enable the Windows System for Linux feature.
Step 2 : Enable Virtual Machine feature by running this command :
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Step 3 : Restart the system and then run this command in PowerShell as Administrator.
wsl --set-deafult-version 2
Step 4 : Installing a Linux Distribution for your choice.
Open the Microsoft Store and select your favorite Linux Distribution. Here are following links for distribution available in Microsoft Store.
- Ubuntu 18.04 LTS
- Ubuntu 20.04 LTS
- openSUSE Leap 15.1
- SUSE Linux Enterprise Server 12 SP5
- SUSE Linux Enterprise Server 12 SP1
- Kali Linux
- Debian GNU/Linux
- Fedora Remix for WSL
- Pengwin
- Pengwin Enterprice
- Alpine WSL
- Raft
Step 5 : Once the Linux distribution of your choice is downloaded from Microsoft office. Open a newly installed Linux distribution, this will take you to Terminal window where rest of the installation will finish. This process will take a few minutes.
You will then need to create a user account and password for your new Linux distribution.
With this, You have successfully set up WSL2 in your windows machine.
Extra
To check list of all Linux Distribution and check which version for WSL it is running.
Use this command in PowerShell :wsl -l -v
To update from WSL 1 to WSL 2 on previously installed Linux distributions
Use this command :wsl --set-version <distro name> 2
To set the default Linux Distribution
Use this command :wsl -s <DistributionName>
orwsl --setdefault <DistributionName>
Run Linux GUI Apps
Prerequisites :
- Windows 11 Build 22000 or higher
- Installed driver for vGPU
- Linux GUI apps are only supported with WSL 2
If you just set-up WSL by using above methods, you're already ready to begin using Linux GUI apps on WSL!
For Existing WSL install
1. Open a command prompt/PowerShell as administrator.
2. Update the WSLwsl --update
3. Shutdown the WSL by running this command
wsl --shutdown
Update the packages in your distribution
Run this command :
sudo apt update
Installing and running GUI-Apps in your distribution
Command for installing a package : sudo apt install <package-name>
Command to launch the package : <package name>
Now, lets install and launch Firefox. To do so, use this command
sudo apt install firefox
sudo apt install firefox
This may some time depending upon your Internet Speed.
firefox
Thank you being with me and reading my article. If you like my post, follow me on Dev.to and do connect with me on LinkedIn and GitHub
Posted on April 1, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024