15

I am running 18.04 LTS on Windows subsystem for Linux (WSL). I have installed the Ubuntu Desktop by running

sudo apt-get install ubuntu-desktop

However, when I start Linux only the terminal starts. How do I get the Desktop to start?

pomsky
  • 68,507
cseligman
  • 151
  • 2
    When it comes to WSL and Ubuntu, I gave it a go and found it frustratingly hard to get the Unity desktop experience to work. There are guides out there, but, what I ended up doing is running Ubuntu in Hyper-V instead. – Stephen Quan Aug 02 '19 at 03:50
  • 4
  • @StephenQuan You should consider posting an answer on that here or on the duplicate link. – WinEunuuchs2Unix Oct 17 '19 at 02:19
  • As of today, GUI apps are natively supported by wsl2 on Windows 10 build 21364+. Detailed blog post: https://devblogs.microsoft.com/commandline/the-initial-preview-of-gui-app-support-is-now-available-for-the-windows-subsystem-for-linux-2/ – Matěj Štágl Apr 22 '21 at 09:15
  • 1
    @MatějŠtágl You can post this as an answer. Hopefully, eventually it will get updated to be the accepted answer. I'm sure there are a number of these types of questions across the Stack Exchange network that will need to be updated. – NotTheDr01ds Apr 23 '21 at 16:59
  • 1
    moderator @Thomas Ward deleted my answer yesterday and converted it to a comment without explaining anything. Just a big lol. Apparently trash mods are not exclusive to SO. – Matěj Štágl Apr 23 '21 at 18:33
  • https://askubuntu.com/users/10616/thomas-ward Thomas feel free to elaborate on what's wrong with my answer – Matěj Štágl Apr 23 '21 at 18:35
  • Honestly, I came back here to comment again, thinking maybe I was jumping the gun on recommending this as an "answer". Since this is still in Insider/Preview, it's probably premature for it to be an answer. This is similar to the current "Hot Meta Post" you'll find on the right which talks about "future release features" being off-topic. – NotTheDr01ds Apr 23 '21 at 20:26

4 Answers4

14

Windows 10 itself does not support GUI. In order to run GUI in wsl you need to install a X server and get it to configure correctly.

I would suggest you to install VcXsrv to display GUI.

I am not able to run GUI successfully by sudo apt-get install ubuntu-desktop. However, I successfully installed mate-desktop GUI in Debian and ubuntu.

Here are the steps for me to display GUI by wsl. You can check my videos on detailed steps Install GUI (mate desktop) to Microsoft Windows Subsystem Linux

step 1: install Debian or Ubuntu Linux subsystem: - PowerShell as administrator: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux - Microsoft Store: install "Debian" or "ubuntu"

step 2: install mate tesktop for Debian: - open Debian in windows 10. Type the following commend - sudo apt-get update - sudo apt install task-mate-desktop

OR install mate-desktop for Ubuntu - open Ubuntu console in windows 10 - sudo apt install tasksel - sudo apt update - sudo tasksel install ubuntu-mate-desktop

step 3: install VcXsrv in windows 10: - download from: https://sourceforge.net/projects/vcxsrv/ - open XLauch, and use the following options for setup - select: "One large window" - Display number: 0 - next - Start no client - next - finish

step 4: setup display in linux console: - export DISPLAY=:0 - export LIBGL_ALWAYS_INDIRECT=1

step 5: start Mate-desktop environment: - run mate-session

Step 3 and step 4 are extremely important to display GUI in windows 10 wsl.

David Xue
  • 199
  • If you repost your answer on the duplicate candidate above your answer will help a larger audience. – WinEunuuchs2Unix Oct 16 '19 at 22:04
  • @WinEunuuchs2Unix Thanks. I will paste my solution to the duplicate candidate – David Xue Oct 17 '19 at 00:27
  • 1
    I was pulling my hair out trying to figure out why this wasn't working. It turns out that these are instructions for WSL version 1. If you are running WSL 2, you need to set export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0

    See https://wiki.ubuntu.com/WSL#Running_Graphical_Applications

    – Josiah Sprague Sep 25 '21 at 11:06
3

As great as WSL is, it's really not designed for that sort of thing.

If your goal is to get the full Ubuntu Desktop, it makes a lot more sense to just install a full Ubuntu Virtual Machine, using something like Virtualbox, Hyper-V, etc. Good luck!

  • thanks, I solved my problem by partitioning my disk and installing a full Ubuntu 19.04 – cseligman Oct 12 '19 at 17:34
  • That is a Dual-boot, which means you never solved the problem posed by your question, which is asking in reference to the tag-name Windows-Subsyem-for-Linux. – JΛYDΞV Sep 25 '21 at 15:52
3

@gus33000 posted a working solution on Twitter:

https://twitter.com/gus33000/status/1188517307867381761

quick rundown for people wanting to recreate this:

Install VcXsrv

Install WSL

Install Ubuntu from the store

sudo apt-get upgrade

sudo apt-get install ubuntu-desktop

sudo service dbus start

sudo service x11-common start

gnome-shell --x11 -r

3

enter image description here The following instructions were copied and pasted from an article I wrote but it lost the original formatting, links, and screenshots:

Source: How to Install Ubuntu Desktop with a Graphical User Interface in WSL2


Download VcXsrv: Visit the official website Click "Download"


Install VcXsrv: Open "vcxsrv-64.1.20.8.1.installer.exe" Click "Next" Click "Install" Click "Close"


Allow Access to VcXsrv: Check "Private Networks" Click "Allow Access"


Open PowerShell: Press "⊞ Windows" Enter "PowerShell" into the search bar Right-click "Windows PowerShell" Click "Run as Administrator"


Open WSL2: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

wsl


Install Ubuntu Desktop: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt --yes install ubuntu-desktop


Set the Username Variable: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

username=$(wslvar USERNAME)


Create the Ubuntu Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

mkdir --parents /mnt/c/users/$username/.ubuntu/


Open the Ubuntu Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

cd /mnt/c/users/$username/.ubuntu


Download Linux Software Repository for Microsoft Products: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

Ubuntu 20.04: wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb --output-document packages-microsoft-prod.deb Ubuntu 18.04: wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb --output-document packages-microsoft-prod.deb


Install Linux Software Repository for Microsoft Products: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo dpkg --install packages-microsoft-prod.deb


Update the Repositories: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt update


Install APT Transport for HTTPS: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt install --yes apt-transport-https


Update the Repositories: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt update


Install .Net: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt install --yes dotnet-sdk-5.0


Add Arkane Systems to the Source List Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo sh -c 'echo "deb [trusted=yes] https://wsl-translinux.arkane-systems.net/apt/ /" > /etc/apt/sources.list.d/wsl-translinux.list'


Update the Repositories: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt update


Install Genie: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

sudo apt install --yes systemd-genie


Create the Sudoers File: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

echo "$USER ALL=(ALL) NOPASSWD:/usr/bin/genie" | sudo EDITOR="tee" visudo --file /etc/sudoers.d/$USER


Create the Desktop Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# CREATE BASH SCRIPT

Store block of text with here document

create_bash_script=$(cat << end_of_string

Define necessary environment variables

export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }'):1.0" export DESKTOP_SESSION="ubuntu" export GDMSESSION="ubuntu" export XDG_SESSION_DESKTOP="ubuntu" export XDG_CURRENT_DESKTOP="ubuntu:GNOME" export XDG_SESSION_TYPE="x11" export XDG_BACKEND="x11" export XDG_SESSION_CLASS="user" export XDG_DATA_DIRS="/usr/local/share/:/usr/share/:/var/lib/snapd/desktop" export XDG_CONFIG_DIRS="/etc/xdg" export XDG_RUNTIME_DIR="$HOME/xdg" export XDG_CONFIG_HOME="$HOME/.config" export XDG_DATA_HOME="$HOME/.local/share" export XDG_CACHE_HOME="$HOME/.cache" export XDG_DESKTOP_DIR="$HOME/Desktop" export XDG_DOCUMENTS_DIR="$HOME/Documents" export XDG_DOWNLOAD_DIR="$HOME/Downloads" export XDG_MUSIC_DIR="$HOME/Music" export XDG_PICTURES_DIR="$HOME/Pictures" export XDG_PUBLICSHARE_DIR="$HOME/Public" export XDG_TEMPLATES_DIR="$HOME/Templates" export XDG_VIDEOS_DIR="$HOME/Videos"

Start desktop environment

gnome-session

end_of_string )

Store username environment variable in lowercase

username=$(wslvar USERNAME | awk '{ print tolower($0) }') &&

Save block of text in bash file

echo "${create_bash_script}" > "/mnt/c/users/$username/.ubuntu/02_start_desktop.sh"


Download the Shortcut Images: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

wget https://assets.ubuntu.com/v1/9fbc8a44-circle-of-friends-web.zip


Unzip the Shortcut Images: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

unzip -o 9fbc8a44-circle-of-friends-web.zip


Create the Shortcut Icon: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

convert -resize 64x64 ./circle-of-friends-web/png/cof_orange_hex.png ubuntu.ico


Exit WSL2: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

exit


Create the VcXsrv Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# RELOAD VCXSRV SCRIPT

Store username environment variable in lowercase

$username = $env:username.tolower()

Store block of text with here-string

$reload_vcxsrv_script = @"

Stop vcxsrv proccess that contains "1.0" in the program window title

get-process vcxsrv | where { `$_.mainwindowtitle -like "1.0" } | stop-process

Start vcxsrv process in a large program window on display number one

start-process "c:\program files\vcxsrv\vcxsrv.exe" -argument ":1 -ac -nowgl -multimonitors -dpms"

"@

Save block of text in powershell file

echo "${reload_vcxsrv_script}" > $env:userprofile/.ubuntu/reload_vcxsrv.ps1


Create the Ubuntu Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# CREATE VISUAL BASIC SCRIPT

Store username environment variable in lowercase

$username = $env:username.tolower()

Store block of text with here-string

$create_vbs_script = @"

' Run PowerShell script in background set application = createobject("shell.application") application.shellexecute "powershell", "-file c:\users\admin.ubuntu\01_reload_vcxsrv.ps1", "", "", 0

' Allow PowerShell script to complete wscript.sleep 3000

' Run Bash script in background set shell= createobject("wscript.shell") shell.run "wsl sudo genie -c bash /mnt/c/users/admin/.ubuntu/02_start_desktop.sh", 0

"@

Save block of text in bash file

echo "${create_vbs_script}" > $env:userprofile/.ubuntu/03_start_ubuntu.vbs


Create the Shortcut Script: Copy the code from below these instructions Paste the code into PowerShell Press "Enter"


# Store block of text with here-string
$create_shortcut_script = @"

Define location variables

$shortcut_location = &quot;$env:userprofile.ubuntu\Ubuntu.lnk" $program_location = &quot;$env:userprofile.ubuntu\03_start_ubuntu.vbs"

Create shortcut

$object = new-object -comobject wscript.shell$shortcut = $object.createshortcut($shortcut_location) $shortcut.targetpath =$program_location $shortcut.iconlocation = &quot;$env:userprofile.ubuntu\ubuntu.ico" `$shortcut.save()

"@

Save block of text in powershell file

echo $create_shortcut_script > $env:userprofile/.ubuntu/04_create_shortcut.ps1


Open the Ubuntu Directory: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

cd c:\users\admin\.ubuntu


Create the Shortcut: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

powershell.exe -file .\04_create_shortcut.ps1


Open the Directory in Explorer: Copy the command from below these instructions Paste the command into PowerShell Press "Enter"

explorer .


Launch the Ubuntu Desktop: Double-click the "Ubuntu" shortcut


Open Terminal: Click "Activities" in the top-left corner Enter "Terminal" into the search bar Click "Terminal"


Disable the Screen Lock: Copy the command from below these instructions Paste the command into Terminal Press "Enter"

gsettings set org.gnome.desktop.screensaver lock-enabled false


Install the Snap Store: Copy the command from below these instructions Paste the command into Terminal Press "Enter"

sudo snap install snap-store


TheAltruist
  • 231
  • 2
  • 4