How to Install Windows Subsystem for Linux WSLg

Windows Subsystem for Linux (“WSLg”) with new features for Windows 11 and Windows 10 – that’s how it’s done

Microsoft previously shipped Windows Subsystem for Linux (WSLg) with Windows 10 by adding from windows features. But with Windows 11 it is also available as a preview via the Store. This version is now officially available. WSL 2 offers new interesting features such as the rendering support for graphical desktop apps. Further the integration of Init-system – systemd.

WSL 2 runs as a Hyper-V virtual machine. This is a change from the bridged network adapter used in WSL 1. This means that WSL 2 uses a NAT service for its virtual network.

WSL Fresh Install

WSLg 2 can be installed from the store. The Cumulative Update November 2022 must be installed in Windows 10 from 21H1, and in Windows 11 KB5020030 or KB5019157. This also in Windows Server 2022 KB5020030. WSL from the Store is also available for Windows Server 2022, although the Store app isn’t available here.

The latest WSL release can be downloaded from GitHub.

C:\> wsl.exe --install --web-download
Install WSL from the Store

Confirm the Windows Account Control with Yes, now WSL is installed from the store. The prompt to create a Linux user appears. This user can be arbitrary and does not have to match the Windows logon.

Reboot + First Launch

After reboot the installation will continue. You’ll be asked to enter a username and password. These will be your Linux credentials, they can be anything you want and don’t have to match your Windows credentials.

the WSL installation ends with information

Windows Subsystem for Linux from Store

Windows Subsystem for Linux (WSL) can also be obtained from the store.

Store App, Windows Subsystem for Linux

According to Microsoft, the store version will become the standard in the future. This is also reflected in the fact that only this version gets new features, which is also revealed by the fact that the update option is only available here.

C:\> wsl.exe --update

The recently released WSL 1.0 integrates support for WSLg, for graphical desktop applications under Linux into Windows. So that a separate installation of the MSI packages for WSL is no longer necessary. It is no longer limited to Windows 11, but also available for Windows 10.

The installed Windows Subsystem for Linux version with the different WSL components shows the following command.

C:\> wsl --version
wsl --version
WSL-Version: 1.0.0.0
Kernelversion: 5.15.74.2
WSLg-Version: 1.0.47
MSRDC-Version: 1.2.3575
Direct3D-Version: 1.606.4
DXCore-Version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows Version: 10.0.22621.819

Now you can install a Linux distribution, the much used Ubuntu can also be obtained from the store.

Ubuntu is sourced from the store

Alternatively, Windows Subsystem for Linux (WSL) can be installed completely along with Ubuntu, from a command prompt with Administrator privilege.

C:\> wsl --install -d Ubuntu

After rebooting, the installation continues. You will be asked to enter a username and password to log in Linux. This user can be arbitrary and does not have to match the Windows logon.

To upgrade an existing WSL installation without WSLg to the latest version of WSL that includes WSLg, then run the update from an elevated command prompt wsl --update

  Note that WSLg is only compatible with WSL 2 and does not work for the WSL distribution configured for WSL in mode 1. Make sure the Linux distribution is configured to run in WSL 2 mode, if does not, you can switch to WSL 2.

Windows Subsystem for (WSLg) Linux GUI Apps

WSLg is the abbreviation for Windows Subsystem for Linux (WSLg) GUI. The purpose of the project is to enable support for running Linux GUI applications (X11 and Wayland) on Windows in a fully seamless integrated desktop experience.

Linux Nautilus in Windows 11 WSLg

WSLg allows Linux GUI Apps natively on Windows

WSLg allows Linux GUI applications to fit natively and naturally on Windows. From integration into the Start menu to display in the taskbar, with Alt-Tab functionality, to applying copy and paste in Windows and Linux applications. WSLg enables seamless desktop integration with cross-workflow using Windows and Linux applications.

WSLg requires WSL in version 2 mode, which is what this tutorial does. The currently installed distribution and the configured WSL version can be listed with the following command, in an elevated command prompt.

C:\> wsl --list -v
  NAME          STATE           VERSION
* Ubuntu        Running         2
  kali-linux    Stopped         2

If you are running version 1 mode, switch to version 2 as follows, which may take a while.

C:\> wsl --set-version ubuntu 2

After that, the computer must be restarted.

Now you need some GUI apps, via the start menu you will find the Ubuntu icon, or you open the Windows Terminal (wt.exe) in which you will also find Ubuntu in the launcher.

Windows Terminal launch Ubuntu

WSLg Linux GUI Apps get from the Bash

Desired GUI apps can now be obtained from the Bash-Terminal.

$ sudo apt update
$ sudo apt install nautilus -y
$ sudo apt install gedit -y
$ sudo apt install x11-apps -y
$ sudo apt install vlc -y
$ sudo apt install nemo -y
$ sudo apt install mc -y
$ sudo apt install geary -y

WSLg Linux GUI App Google Chrome Browser

If your preferred browser is Google Chrome, it can be installed with the following lines.

cd /tmp
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb 
sudo apt install --fix-broken -y
sudo dpkg -i google-chrome-stable_current_amd64.deb

Although Firefox has overtaken Google Chrome in number of users, it is still very popular in the Linux world due to the Mozilla Foundation’s privacy-friendly features. The Linux version can also be easily installed with apt from the Ubuntu repository with apt install firefox

Install and run GUI Apps

Once these GUI apps are installed, you can find the apps in the Start menu under All apps with the name of the distribution.

the apps in the Start menu under the name of the distribution

The GUI apps can also be launched using the commands in the terminal window.

  • nautilus
  • xclock
  • gedit
  • geary
  • google-chrome
  • nemo
  • mc

GitHub Sources Link: github.com/microsoft/wslg

WSLg, Windows Subsystem for Linux GUI Desktop
Windows Subsystem for Linux GUI Apps

Developer Feature VS Code in WSL

The VS Code WSL extension allows to save project files in the Linux file system using the Linux command line tools. it allows shared access to files from Linux (WSL) as well as from the windows host system. To create, debug or run a project in web browser in VS Code on Windows without using Performance degradation.

quote  You might also be interested in the related post here.

While WSL2 provides the complete command line experience to any developer, it is still not a complete replacement for actual Installation on a Virtual machine .

How to Check and Set Linux systemd Runlevels

Runlevel today implemented on systemd, previously most Linux distributions were equipped with the init system, Sys-V style. Sys-V used seven different runlevels to determine which processes can be started on the system. For example, runlevel 3 was usually reserved for the command line and associated programs, while runlevel 5 launched a GUI and all the processes required to do so. Results may vary by distribution.

The vast majority of Linux distributions have adopted systemd as their init system. Some distributions still use Sys-V where the traditional implementation of runlevels still exists. The systemd implementation adopted the concept of runlevels, converting them to systemd “targets”.

On some systems there are still scraps of Sys-V, on which commands such as runlevel can still be found. But some modern systemd distributions have completely eradicated this support. In this tutorial we show how to check the current runlevel on Linux.

Check current Linux runlevel?

Check current Linux runlevel?

Below are two commands to determine the current Linux runlevel.

$ runlevel
N 5
$ who -r
  run-level 5 2022-11-07 14:52

As you can see, runlevel 5 has started here. Alternatively, the command who -r can be ran. The runlevel command is only available on some systemd distributions, but should work on any sys-V system.

The different runlevels were assigned to corresponding systemd targets. This command can be used to check the targets.

$ ls -l /lib/systemd/system/runlevel*

Below is the output of the runlevels at a Linux Mint, which is based on Ubuntu/Debian.

$ lrwxrwxrwx 1 root root 15 Aug 31 17:27 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx 1 root root 13 Aug 31 17:27 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx 1 root root 16 Aug 31 17:27 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx 1 root root 13 Aug 31 17:27 /lib/systemd/system/runlevel6.target -> reboot.target

/lib/systemd/system/runlevel1.target.wants:
Total 0

/lib/systemd/system/runlevel2.target.wants:
Total 0

/lib/systemd/system/runlevel3.target.wants:
Total 0

/lib/systemd/system/runlevel4.target.wants:
Total 0

/lib/systemd/system/runlevel5.target.wants:
Total 0

Linux Runlevels

0Halt shut down the system
1Single-user mode (Rescue and special administration)
2Multi-user mode not start network interfaces and daemons
3Multi-user mode with Networking starts system normally
4Not Used
5Multi-user mode as runlevel 3 + display manager X11 GUI
6Reboot the system

As with runlevels, there are 7 systemd targets by default. The two main targets are multi-user.target and graphical.target. The following command displays the default systemd targets.

$ systemctl get-default
graphical.target

In this example, graphical.target is started, which makes sense because we need a graphical desktop environment. On a server where often no GUI is running, multi-user.target is usually started.

$ systemctl get-default
multi-user.target

Use the command to see which services are associated with this target.

$ systemctl list-dependencies graphic.target
graphic.target

Try the following command to see which systemd target (or runlevel) a service needs to run. In this example, we check the SSH service.

$ systemctl show -p WantedBy sshd.service
WantedBy=multi-user.target

How to set systemd?

The Linux systemd runlevel can be set with this command.

$ sudo systemctl set-default multi-user.target

The next time the system boots in multi-user mode (multi-user.target).