Skip to content

Instantly share code, notes, and snippets.

@blockspacer
Last active January 17, 2024 17:32
Show Gist options
  • Save blockspacer/9359705ca150ea101b95ea74fb3d850c to your computer and use it in GitHub Desktop.
Save blockspacer/9359705ca150ea101b95ea74fb3d850c to your computer and use it in GitHub Desktop.
Install WSL2 & VcXsrv & systemd & plasma KDE & snap
Install Windows Terminal https://github.com/hubisan/emacs-wsl#use-windows-terminal

Install VcXsrv https://sourceforge.net/projects/vcxsrv/

Close everything and go to Windows Firewall with Advanced Security -> Inbound rules and delete every rule you see for Vcxsvr.exe. After that the first time you launch Vcxsvr make sure you Allow access for Private AND Public networks.

Search for VcXsrv entries (there should be two) and disable all found.

# see https://github.com/microsoft/WSL/issues/6181
Start XLaunch on Windows
    Select Multiple Windows (default)
    Select Start no client (default)
    Check✅ Disable access control
    Uncheck ☐ Native opengl
    Save configuration on startup folder, location %AppData%\Microsoft\Windows\Start Menu\Programs\Startup
    Do this for safe side https://github.com/microsoft/WSL/issues/4106#issuecomment-502996203 Right click on the shortcut to the application and select properties. On the box where it is the path to the app, append -ac.

Allow Access to VcXsrv: Check "Private Networks" Click "Allow Access" https://stackoverflow.com/a/64233268

# 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"
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all

# see https://github.com/microsoft/WSL/issues/4106
New-NetFirewallRule -DisplayName "WSL2" -Direction Inbound  -InterfaceAlias "vEthernet (WSL)"  -Action Allow

Install WSL https://maurogiusti.medium.com/running-ubuntu-on-windows-10-with-wsl2-c4f06b3c353

Read https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-10#1-overview

wsl --set-default-version 2

wsl --status

wsl -l -v

Install Ubuntu from the store

wsl --set-version <Ubuntu-Distro> 2

Run Ubuntu

uname -a
lsb-release -a

sudo apt-get update
sudo apt-get upgrade

sudo apt install -y language-pack-en language-pack-en-base manpages
sudo locale-gen en_US.UTF-8
sudo update-locale LANG=en_US.UTF8

sudo apt install wslu
wslvar --getsys

sudo apt install --yes curl mesa-utils iptables-persistent 
sudo apt install --yes lvm2 gparted build-essential git subversion 
sudo apt install --yes exfat-fuse net-tools sqlitebrowser gdb rsync snapd flatpak cntlm
sudo apt install --yes apt-transport-https gpg
sudo apt install --yes x11-apps daemonize dbus-user-session fontconfig xdg-utils binutils
sudo apt install --yes binutils dbus-x11

sudo apt-get install openssh-server
ssh-keygen -t ed25519 -C "email@example.com"

# NOTE: changed ssh Port to 2200 https://github.com/microsoft/WSL/issues/734#issuecomment-240440522
sudo nano /etc/ssh/sshd_config
Port 2200
ListenAddress 0.0.0.0    
UsePrivilegeSeparation no 
PasswordAuthentication yes

# NOTE: changed ssh Port to 2200 https://github.com/microsoft/WSL/issues/734#issuecomment-240440522
sudo service ssh --full-restart

sudo apt install x11-xkb-utils
setxkbmap -layout us

Install https://learn.microsoft.com/ru-ru/dotnet/core/install/linux-ubuntu

wget https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-6.0 aspnetcore-runtime-6.0 dotnet-runtime-6.0
# NOTE: microsoft's systemd implementation only works on Windows 11
Install systemd https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/

Read https://ubuntu.com/blog/ubuntu-wsl-enable-systemd

sudo nano /etc/wsl.conf
[boot]
systemd=true

 wsl.exe --shutdown
 
 systemctl list-unit-files --type=service
wsl --update

sudo apt install kde-plasma-desktop

Open up your ~/.bashrc:

nano ~/.bashrc
And paste this in at the end and save:

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):1.0

# see https://github.com/microsoft/WSL/issues/2855
export LIBGL_ALWAYS_INDIRECT=1

# see https://stackoverflow.com/a/65244718
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"

gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.desktop.session idle-delay 0

sudo su $USER -c 'startplasma-x11'
wsl --update

# https://github.com/microsoft/WSL/issues/2374
sudo apt install --reinstall snapd

snap version

systemctl status snapd.service
sudo snap install snap-store

FIX (workaround only works until the terminal is closed, using WSL2 Ubuntu 20.04 on Windows 10 21H2): https://github.com/microsoft/WSL/issues/2374#issuecomment-1049954771
sudo apt-get update && sudo apt-get install -yqq daemonize dbus-user-session fontconfig
sudo daemonize /usr/bin/unshare --fork --pid --mount-proc /lib/systemd/systemd --system-unit=basic.target
exec sudo nsenter -t $(pidof systemd) -a su - $LOGNAME

sudo snap install core
sudo snap install shutter
sudo snap install vlc
sudo snap install firefox
sudo snap install chromium
sudo snap install thunderbird

wsl --update

read https://www.linuxuprising.com/2021/03/how-to-get-sound-pulseaudio-to-work-on.html

The WSL environment does not support audio, but it can be enabled by installing the PulseAudio server on Windows following this guide. https://x410.dev/cookbook/wsl/enabling-sound-in-wsl-ubuntu-let-it-sing/

With the latest wslu package installed the starting Ubuntu app detects the running PulseAudio server and enables audio. sudo apt install --yes wslu

sudo apt-get install alsa-tools-gui pavumeter pavucontrol

See script from https://askubuntu.com/a/1265411

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