Setting Up WSL2 - alarwasyi98/dotfiles-win GitHub Wiki
Developers can access the power of both Windows and Linux at the same time on a Windows machine. The Windows Subsystem for Linux (WSL) lets developers install a Linux distribution (such as Ubuntu, OpenSUSE, Kali, Debian, Arch Linux, etc) and use Linux applications, utilities, and Bash command-line tools directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.
You must be running Windows 10 22H2 (Build 19041 or higher) or Windows 11 to have WSL Capabilities on your Windows machine.
- Windows 10/11
- (Feature) Windows Subsystem for Linux
- (Feature) Virtual Machine Platform
To enable the Virtual Machine Platform and Windows Subsystem for Linux features on your Windows machine using the command line, you can use the DISM (Deployment Image Servicing and Management) tool. Here are the steps and commands to do that:
You can run the following complete script to enable both features and then restart your system:
# Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
# Enable Windows Subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
# Restart the computer
Restart-Computer
If you don't familiar with DISM and decide to run Powershell, you can run this command:
# Enable Virtual Machine Platform
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
# Enable Windows Subsystem for Linux
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
# Restart the computer
Restart-Computer
Make sure you have all requierements above to running Linux on your Windows machine. Run this command to get latest version of WSL.
wsl --update
Important
It's recommended to have WSL Version 2.4.4 or above to running any available distro properly. Run wsl --version to verify.
After the installation process is finished, restart your computer! list all available distribution that can be installed in with:
wsl --list --online
ArchLinux became an officially supported WSL distribution in March 2025, and I'm happy to check it out.
wsl --install archlinux
# Get install
wsl --install archlinux
# Turn off WSL
wsl --shutdown -d [distro]
# Terminating distro
wsl --terminate -d [distro]
# Uninstall distro
wsl --unregister -d [distro]
Caution
Don’t use wsl --uninstall
command to remove a distro. It will completely remove WSL itself from your computer
Tip
Keep in mind that the images are built regularly, it is strongly recommended running pacman -Syu
right after the first launch due to the rolling release nature of Arch Linux.
Locale are used by glibc and other locale-aware programs or libraries for rendering text, correctly displaying regional monetary values, time and date formats, alphabetic idiosyncrasies, and other locale-specific standards.
To display the currently set locale and its related environmental settings, type:
locale
to list all enabled locales, type:
locale --all-locales
set the default locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
echo "LC_ALL=en_US.UTF-8" >> /etc/environment
locale-gen en_US.UTF-8
Note
locale-gen
is used for generate the locale, and UTF-8
is recommended over other character sets
This operation will configure Elevated Rights for Non-Root Users. By default, WSL launches as the root
user. This step grants your user account elevated privileges to run commands without sudo
.
Install sudo
, git
, vim
and vi
as prerequisites
pacman -S sudo git vim vi
To modify sensitive system files, which is visudo
, run the following commands as the root
user. If you're currently logged in as a different user, first elevate privileges by executing:
sudo su
And then, execute these conmands:
# Give the user sudo acceess
EDITOR=vi visudo
# Scroll down and Uncomment this line
%wheel ALL=(ALL:ALL) ALL
# alternative oneliner command
echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel
Tip
Always validate visudo
after editing and make sure everything's good.
sudo visudo -c
Congratulation Pal! Now your user has sudo access and could eliminate any commands.
When you first launch WSL, you’re automatically logged in as root
. To give the root
user a password, type:
passwd
Type carefully: Password characters are invisible. Use a strong password (12+ chars, mix of cases/numbers/symbols).
So let's create a new users using following command, the command would create a directory based on your username, input your username into groups, and set bash as default login shell.
useradd --create-home --groups wheel --shell /bin/bash yourusername
passwd yourusername
To setup default user in WSL is kinda different with OG Arch Linux. Set default user login by edit /etc/wsl.conf
file and write down this letter:
[user]
default=yourusername
echo "[user]" | sudo tee -a /etc/wsl.conf
echo "default=yourusername" | sudo tee -a /etc/wsl.conf
If you're lost, you can use this PowerShell command to set default user-login. ensure that the user has been created.
wsl --manage archlinux --set-default-user <username>
The change will apply at the next session. To terminate your current session, run the following command in a PowerShell prompt:
wsl --terminate archinux
pacman
stands for Package Manager is the default on your arch system. WSL is sutomatically generate keyring so you dont have to do this anymore.
sudo pacman-key --init
sudo pacman-key --populate
sudo pacman -Sy archlinux-keyring
sudo pacman -Su
Update all of packages repo(s) and upgrade them. It's like running sudo apt-update && sudo apt-full-upgrade
in Ubuntu
sudo pacman -Syuu
Tip
We can do more modification for pacman
to show us "eye candy" as progress bar. I'll show you how. Type this first:
sudo vim /etc/pacman.conf
You will prompted to /etc/pacman.conf
file which is the pacman
config file. Uncomment or append these following lines:
Color
VerbosePkgLists
ParallelDownloads=5
ILoveCandy
If you still can't see the "eye candy", comment NoProgressBar
In the other hand, yay
and paru
is an Arch User Repository (AUR). AUR is a community driven repository by Arch users. If you want to add yay
and paru
as alternative to pacman
, do these steps:
Warning
Make sure you have base-devel
installed properly to build the packages
# yay
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si
# paru
sudo pacman -S --needed base-devel
git clone https://aur.archlinux.org/paru.git
cd paru
makepkg -si
There's several programs to make everything running properly. Here's the list of configured packages of the dotfiles.
# Code Editor
sudo pacman -Sy vi vim neovim nano
# Shell(s)
bash bash-completion fish zsh zsh-autocomplete zsh-autosuggestions zsh-syntax-hightlighting zsh-history-substring-search
# CLI Tools
sudo pacman -Sy bat fzf fd ripgrep zoxide stow eza curl wget zip unzip jq trash-cli tmux lazygit starship git-delta
# Fonts
sudo pacman -Sy ttf-firacode-nerd ttf-hack-nerd
# Neovim dependencies
sudo pacman -Sy --needed neovim git wget curl lazygit base-devel fzf ripgrep fd
# Some interesting tools
googler #cli-browser
xdg-user-dirs # well-known directory
### ONELINER ###
sudo pacman -Sy base-devel vim neovim bash bash-completion fish zsh zsh-autocomplete zsh-autosuggestions zsh-syntax-highlighting zsh-history-substring-search bat fzf fd ripgrep zoxide stow eza curl wget zip unzip jq trash-cli tmux lazygit starship git-delta
# Miscellaneous
yay -S shell-color-scripts-git # show unique ASCII
Seting up everything from scratch will take a long time. There's several ways to automate task in Linux and UNIX system. However, we will take the dotfiles method which is popular method around Linux community to automate simple even complex tasks.
I use stow
as my dotfiles manager. Stow is a GNU utility that organizes configuration files into a central directory and creates symbolic links to their proper system locations.
# Dotfiles Installation
git clone https://github.com/alarwasyi98/dotfiles ~/.dotfiles
cd .dotfiles
stow .
# or
stow <apps> # i.e stow nvim | and so on