Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
News

Linux GUI Applications on Windows Subsystem for Linux

linuxguiapplicationsonwindowssubsystemforlinux2

Windows 11 added full GUI and X windows support to the Windows Subsystem for Linux (WSL2).

In this post, you’ll join a webinar to learn more about WSL2, how it works, how to properly configure it, and how to target it in your application development. Without the need for a second computer or the overhead of a virtual machine, you can test your Linux applications on your Windows desktop. With these topics, you’ll learn how to make use of additional Linux features and APIs in your applications with the use of Windows IDE.

Windows Subsystem for Linux

  • Introduced in Windows 10
    • Trivia: Replaces Windows Services for Unix from 2004
    • Also available on Windows 11 and Windows Server 2019
  • Developed in collaboration with Canonical and others
  • WSL2 improved performance with a real Linux kernel
    • Uses a subset of Hyper-V features
  • Not as isolated or as much overhead as a VM
    • Performance rivals native Linux
  • WSLg adds GUI support ○ Ships in Windows 11 or Windows 10 Insider 21364

Microsoft & Linux (addressing the elephant in the room…)

l01-3713256

Benefits and Use Cases

  • Ability to run unmodified ELF64 Linux binaries, expand toolkit and capabilities
  • Flexibility of combining Windows and Linux tool chain on one computer
  • Less overhead than a traditional virtual machine means better performance
  • Local build environment with containers, etc.
  • Testing server applications from Windows without additional infrastructure
  • No need to mess with dual boot or 3rd party VM installation
  • Invoke Linux binaries from Windows and Windows executables from Linux
  • Runs as you need it, less management
  • Memory and drive space are dynamically shared

WSL Installation Guide

  • Enable the “Windows Subsystem for Linux” optional feature (via Admin PowerShell or Windows Features)
    • Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  • Install Linux Distro of Choice
    • Windows Store or manually via script
  • Launch Linux Distro to initialize it, provide password, etc.
  • You can also build a custom distro
  • Launch WSL 4 ways
    • Icon on start menu
    • [distro], for example ubuntu
    • wsl.exe or bash.exe
    • wsl [command] or bash -c [command]
  • https://docs.microsoft.com/en-us/windows/wsl/install

Available Distributions

  • Ubuntu, Kali, & Pengwin are in the
  • Debian family (using .deb pkgs – apt)
    • Kali is focused on security
    • Pengwin is designed around WSL
  • SUSE and Fedora are in the RPM family with Red Hat
  • Alpine is an independent, lightweight, security-oriented, Linux distribution
  • Some distros include multiple versions

Managing WSL Distros

  • List distributions
    • wsl –list –all or wsl –list –running
  • Set default distribution
    • wsl –setdefault <DistributionName> or wsl -s <DistributionName>
  • Run a specific distro
    • wsl –distribution <DistributionName>
  • Run as specified user
    • wsl –user <Username> (or use the specific distro name)
  • Unregister and uninstall a distribution
    • wsl –unregister <DistributionName>
  • Shutdown all WSL instances
    • wsl –shutdown

First Run

  • On first run you are usually prompted for a username and password
  • openSUSE uses YaST2 for a nice ASCII GUI

Connecting from the IDE

  • Tools -> Options -> Deployment -> Connection Profile Manager
  • The IP address and ports are shared with the host
  • So you connect to 127.0.0.1
  • Can only use each port number once (even if you have multiple distros setup)
  • So use different port numbers for multiple instances if you want to run them simultaneously

Linux User Password Reset

  1. Note your username
  2. From Windows terminal get the distro name
    • wsl -l
  3. From Windows terminal switch default-user to root
    • ubuntu config –default-user root
  4. Launch the WSL distro (you will be logged in as root)
    • ubuntu
  5. Change the user’s password
    • passwd username
  6. Change the default user back
    • ubuntu config –default-user username
  7. Launch the WSL distro again

Accessing Files Between Systems

  • Access Windows from Linux
    • cd /mnt/c/
  • Open WSL in current Windows directory
    • wsl
    • wsl -d ubuntu
    • ubuntu
  • Access Linux from Windows
    • wsl.localhost
  • Open current Linux path from Windows
    • explorer.exe .
    • cmd.exe
    • powershell.exe

Windows Subsystem for Linux resources

More WSL Resources

FMXLinux Resources

Setting up CentOS (Redhat based)

  • Install Docker in Ubuntu docs.docker.com/engine/install/ubuntu/
  • Follow steps docs.microsoft.com/en-us/windows/wsl/use-custom-distro
    • Make folder on Windows C:WSLCentOS
    • From Ubuntu
      • sudo service docker start
      • sudo docker run -t dokken/centos-stream-9 bash ls /
      • dockerContainerID=$(sudo docker container ls -a | grep -i dokken/centos-stream-9 | awk ‘{print $1}’)
      • sudo docker export $dockerContainerID > /mnt/c/WSL/CentOS/centos.tar
      • sudo docker rm $dockerContainerID
    • From PowerShell
      • cd C:WSLCentOS
      • wsl –import CentOS C:WSLCentOS .centos.tar
    • From CentOS
      • yum update -y && yum install passwd sudo -y
      • myUsername=jim
      • adduser -G wheel $myUsername
      • echo -e “[user]ndefault=$myUsername” >> /etc/wsl.conf
      • passwd $myUsername
    • From PowerShell
      • wsl –terminate CentOS

l04-2

Do you want to create Linux GUI Applications on Windows?
Try out the Windows IDE and make the most of it. Request a Free Trial here.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Chief Developer Advocate for Embarcadero Technologies.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES