Set up a WSL development environment using Arch Linux.
Ensure that virtualization is enabled in the BIOS and that the Windows Subsystem for Linux
optional component is enabled.
> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Install the Windows Subsystem for Linux
from the Microsoft Store, which is now the default.
Note: You no longer should enable the “Windows Subsystem for Linux” optional component, or install the WSL kernel or WSLg MSI packages as they are no longer needed.
Using the Store version of WSL allows you to get updates to WSL much faster compared to when it was a Windows component. WSLg is also now bundled.
To update to the latest stable version of WSL and WSLg, simply run wsl --update
from an elevated command prompt or powershell.
> wsl --update
To update to the latest pre-relase version, run instead:
> wsl --update --pre-release
WSL can be installed with Ubuntu as a default distribution (wsl.exe --install
) or with a pre-defined distribution (wsl.exe -l -o
) with the -d
parameter.
It can also be used with any custom Linux distribution.
We will install Arch Linux as a custom WSL distribution launcher package.
Download and extract the latest online installer Arch_Online.zip
archive from the ArchWSL project, for example in C:\Linux\
.
Run the executable:
PS C:\Linux > Arch.exe
You can check that the distribution has been installed and registered as default with WSL:
> wsl.exe -l
Windows Subsystem for Linux Distributions:
Arch (Default)
You can launch WSL from the added Windows Terminal entry.
After the installation, you have access to a root shell.
[root@HOSTNAME]#
Set the root password:
# passwd
New password:
Retype new password:
passwd: password updated successfully
Please see Sudo and User and groups pages.
Add user:
# useradd -m -G wheel -s /bin/bash <username>
Set default user password:
# passwd <username>
New password:
Retype new password:
passwd: password updated successfully
Adjust default user sudo permissions in /etc/sudoers
using visudo
.
# export EDITOR=vim
# visudo /etc/sudoers
## Uncomment to allow members of group wgeel to execute any command
> %wheel ALL=(ALL) ALL
Exit and set the default user of the Arch WSL instance:
# exit
> Arch.exe config --default-user <username>
Adjust WSL config in /etc/wsl.conf
:
#
# /etc/wsl.conf
#
# See https://docs.microsoft.com/en-us/windows/wsl/wsl-config
# systemd support
[boot]
systemd=true
# automount settings and options
[automount]
enabled = true
mountFsTab = true
root = /mnt/
options = "metadata,umask=22,fmask=11"
# network settings
[network]
generateHosts = true
generateResolvConf = true
# interop settings
[interop]
enabled = true
appendWindowsPath = true
Initialize and configure the pacman package manager.
Enable the VerbosePkgLists
option to have a nicer display.
$ sudo vim /etc/pacman.conf
Select a packages mirror close to your location.
$ sudo vim /etc/pacman.d/mirrorlist
Initialize the keyring of the pacman
package manager:
$ sudo pacman-key --init
$ sudo pacman-key --populate
$ sudo pacman -Sy archlinux-keyring
$ sudo pacman -Su
In ~/.zshrc
, set the default editor:
# editor
export EDITOR=nvim
export VISUAL=nvim
In /etc/sudoers
, set the default editor for sudo
:
Defaults editor=/usr/bin/nvim
Install an AUR helper to easily access the Arch User Repository. We will use auracle to semi-automate the process.
Ensure base-devel
is installed:
$ sudo pacman -S base-devel
Install git
:
$ sudo pacman -S git
Clone the auracle-git
package:
$ cd ~
$ mkdir aur && cd aur
$ git clone https://aur.archlinux.org/auracle-git.git
Build and install the package:
$ cd auracle-git
$ makepkg -si
The helper is now available to search and download packages.
To check for outdated packages, run:
$ auracle outdated
fakeroot-tcp 1.25.3-2 -> 1.31-1
As an example, a newer version of the fakeroot-tcp
package is available.
To update packages:
$ auracle update
$ cd fakeroot-tcp/
$ makepkg -si
Bash is the default command-line shell, but Zsh is a good alternative due to its improved interactive experience, richer scripting capabilities, extensibility.
$ sudo pacman -S zsh
Make it the default shell:
$ chsh -s /bin/zsh
In ~/.zshrc
, add:
export BROWSER="pwsh.exe /C start"
Known issues and resolution.
To avoid time desynchronization after waking up from sleep, enable the time synchronization daemon.
Ensure systemd is enabled at boot in /etc/wsl.conf
:
[boot]
systemd=true
Adjust systemd config to enable time synchronization:
sudo systemctl edit systemd-timesyncd
Override the setting by adding these 2 lines:
### Editing /etc/systemd/system/systemd-timesyncd.service.d/override.conf
[Unit]
ConditionVirtualization=
### Line below this comment will be discarded
Enable and start the service:
sudo systemctl enable systemd-timesyncd
sudo systemctl start systemd-timesyncd
Check the status with:
timedatectl status
timedatectl timesync-status
Running sudo pacman -Syu
results in a warning:
/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link
Replace the duplicated files with symlinks:
cd /usr/lib/wsl/lib
sudo rm libcuda.so libcuda.so.1
sudo ln -s libcuda.so.1.1 libcuda.so.1
sudo ln -s libcuda.so.1 libcuda.so
sudo ldconfig
WSL does not release disk space back to the host OS automatically.
To automatically shrinks the WSL virtual hard disk (VHD) as you use it, create a .wslconfig
file in C:\Users\<UserName>\
:
[experimental]
sparseVhd=true