Skip to content

Instantly share code, notes, and snippets.

@b23prodtm
Last active December 16, 2023 04:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save b23prodtm/b058b8b0efbd7e9c632dbcc7affe1754 to your computer and use it in GitHub Desktop.
Save b23prodtm/b058b8b0efbd7e9c632dbcc7affe1754 to your computer and use it in GitHub Desktop.
How to install Gnome for Ubuntu 22.04 on WSL2?
#!/usr/bin/env bash
if [ -z $(command -v wslvar) ]; then printf "%s\n" "Install package wslu please" ; sleep 2; exit 0; fi
username=$(wslvar USERNAME | awk '{ print tolower($0) }' )
mkdir -p --parents "/mnt/c/users/$username/.ubuntu/"
cd "/mnt/c/users/$username/.ubuntu"
if [ ! -f /etc/apt/sources.list.d/microsoft-prod.list ]; then
sudo apt-key adv --fetch-keys https://packages.microsoft.com/keys/microsoft.asc
sudo apt update
fi
if [ ! -f /etc/apt/sources.list.d/wsl-transdebian.list ]; then
sudo wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg
sudo chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
sudo cat << EOF > /etc/apt/sources.list.d/wsl-transdebian.list
deb https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ $(lsb_release -cs) main
EOF
sudo apt update
fi
if [ -z $(sudo apt install --yes systemd-genie > /dev/null) ]; then
if [ ! -f /etc/sudoers.d/$USER ]; then
echo "$USER ALL=(ALL) NOPASSWD:/usr/bin/genie" | sudo EDITOR="tee" visudo --fil> fi
fi
# CREATE BASH SCRIPT
# Save block of text in bash file
cat << EOF > "/mnt/c/users/$username/.ubuntu/02_start_desktop.sh"
# Define necessary environment variables
export DISPLAY="\$(cat /etc/resolv.conf | grep nameserver | awk '{ print \$2 }'):0.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
EOF
@b23prodtm
Copy link
Author

@b23prodtm
Copy link
Author

Credits to : MediumDavid L

@b23prodtm
Copy link
Author

To startup a gnome session with GWSL (X11 server for windows)

login to BASH in ubuntu WSL2 and use keyboard commands:

sudo systemctl start dbus
gnome-session

gnome-session [options]:
--debug enable debugging in shell terminal
-f fail-safe

@b23prodtm
Copy link
Author

b23prodtm commented Dec 20, 2022

How to share an USB mass storage here datailed for Ubuntu in WSL

E.g. usbipd wsl attach -b 1-3 -d Ubuntu-Preview will attach my USB mass storage device to the Ubuntu-Preview terminal session
There is a new graphical interface for usbip

@opslocs
Copy link

opslocs commented Dec 30, 2022

The Code is not working for me.
I get an Error because Failed to fetch https://wsl-translinux.arkane-systems.net/apt/InRelease Could not resolve 'wsl-translinux.arkane-systems.net' and ./wsl2-setup-desktop-gnome.sh: line 56: syntax error: unexpected end of file`. The secound one looks like a Problem with the visudo command.

@b23prodtm
Copy link
Author

Updated from scratch in gist with latest Arkane systems genie repository

@farag2
Copy link

farag2 commented Feb 10, 2023

The same error happens for me too: Failed to fetch https://wsl-translinux.arkane-systems.net/apt/InRelease Could not resolve 'wsl-translinux.arkane-systems.net' and ./wsl2-setup-desktop-gnome.sh: line 56: syntax error: unexpected end of file.

@danktankk
Copy link

danktankk commented Mar 1, 2023

Same:

Some index files failed to download. They have been ignored, or old ones used instead.
./wsl2-setup-desktop-gnome.sh: line 56: syntax error: unexpected end of file

@toanphuong
Copy link

Run script raised error:
The repository 'https://ppa.launchpadcontent.net/communitheme/ppa/ubuntu jammy Release' does not have a Release file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment