01 Oct 2024 - by 'Maurits van der Schee'
So, maybe your employer want you to use Windows. Obviously you still want to use Linux as you want to run whatever operating system your production servers run. If running Virtualbox or VMWare causes too much switching between environments then WSL might be a solution. In this post I'll show how to install WSL 2 with Debian 12 as the Linux distribution. First we show which Linux distributions you can choose from, by running (from the command prompt):
wsl --list --online
Output is:
The following is a list of valid distributions that can be installed.
The default distribution is denoted by '*'.
Install using 'wsl --install -d <Distro>'.
NAME FRIENDLY NAME
* Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
Ubuntu-24.04 Ubuntu 24.04 LTS
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_7 Oracle Linux 8.7
OracleLinux_9_1 Oracle Linux 9.1
openSUSE-Leap-15.6 openSUSE Leap 15.6
SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5
SUSE-Linux-Enterprise-15-SP6 SUSE Linux Enterprise 15 SP6
openSUSE-Tumbleweed openSUSE Tumbleweed
If you want to install Debian, you run:
wsl --install --distribution Debian
Output:
Installing: Virtual Machine Platform
Virtual Machine Platform has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Installing: Windows Subsystem for Linux
Windows Subsystem for Linux has been installed.
Installing: Debian GNU/Linux
Debian GNU/Linux has been installed.
Now we have to restart Windows to enable WSL (v2). Then we see:
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username: maurits
Adding user `maurits' ...
Adding new group `maurits' (1000) ...
Adding new user `maurits' (1000) with group `maurits (1000)' ...
Creating home directory `/home/maurits' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
No password has been supplied.
New password:
Retype new password:
No password has been supplied.
New password:
Retype new password:
No password has been supplied.
passwd: Authentication token manipulation error
passwd: password unchanged
Try again? [y/N] N
Changing the user information for maurits
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
Adding new user `maurits' to supplemental / extra groups `users' ...
Adding user `maurits' to group `users' ...
We can see the running WSL from a command prompt:
wsl --list -v
Output is:
NAME STATE VERSION
* Debian Running 2
See how we didn't enter a password? It is not really required. Now open a windows prompt:
wsl -u root
Now type the following from within WSL to allow sudo without a password:
echo "maurits ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Now you can exit and start the WSL again and use "sudo" without a password. Install some requirements from WSL:
sudo apt -y update && sudo apt -y upgrade
sudo apt install git wget htop curl
Now also enable systemd (for running MariaDB for instance) by running:
sudo nano /etc/wsl.conf
And in this (new) file add:
[boot]
systemd=true
Download and install VS Code installer (VSCodeUserSetup-x64-1.93.1.exe) in windows from:
https://code.visualstudio.com/
And follow the installer wizard, next, next, next, finish :-)
Next install the "WSL" extension in VS Code to allow access to your Debian environment.
Now restart your WSL using the following command from the windows prompt:
wsl --shutdown
Now ensure you have a SSH key in your WSL by running from within WSL:
ssh-keygen
Now echo the public key and add it to your Github profile:
cat ~/.ssh/id_rsa.pub
Optionally install some PHP development requirements I often use:
sudo apt install mariadb-server mariadb-client memcached php php-mysql php-memcache \
php-zip php-intl php-mbstring php-cli php-gd php-xml php-curl php-yaml
After doing that you can clone a repository and start VS code from within WSL:
git clone git@github.com:mevdschee/php-crud-api.git
cd php-crud-api
code .
After starting VS Code the following should appear:
Updating VS Code Server to version ...
Removing previous installation...
Installing VS Code Server for Linux x64 (...)
Downloading: 100%
Unpacking: 100%
Unpacked 1765 files and folders to ...
Looking for compatibility check script at .../bin/helpers/check-requirements.sh
Running compatibility check script
Compatibility check successful (0)
You may have to run the last command twice to start VS Code. Don't forget about "PHP Intelephense (by Ben Mewburn)" and "PHPStan (by swordev)" extensions if you are doing PHP development.
The command "htop" on the WSL command-line will show the RAM and CPU usage of the WSL VM. If you feel that there is not enough RAM or CPU threads available in the WSL you can change the 2 CPU 4GB RAM default by making a config file in Windows using:
notepad.exe %UserProfile%/.wslconfig
And enter "8GB" for the memory and "4" for the processors (or another value):
[wsl2]
#Limits VM memory, this can be set as whole numbers using GB or MB
memory=8GB
#Sets the VM to use a number of virtual processors
processors=4
Now stop the WSL using:
wsl --shutdown
And start it again by clicking the nice Debian logo from the start menu to make the configuration effective. In the Windows Task Manager you will see "Vmmem" process representing the WSL machine.
NB: If you run WSL in Win10 pro in KVM on Linux (as I do) then set the sockets in KVM to a maximum of 2 and increase the core count of your VM instead.
Enjoy!
PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.