Install WSL and its Dependencies.
wsl --install --no-distribution
Windows Configuration
Set WSL 2 as your default version
wsl --set-default-version 2
Note
You may need to download the WSL2 Kernel update. This can be found here. Afer that is installed just run the command above and then follow the guide from there.
Create .wslconfig file
The next step is to create a .wslconfig
file so you can add more control over WSL.
- In a
Powershell
shell. Copy That and boom you should be good.
@"
[wsl2]
memory = 4G
[experimental]
autoMemoryReclaim = gradual
sparseVhd = true
"@ | Out-File -FilePath "$env:USERPROFILE\.wslconfig" -Encoding utf8
This gets posted on your Windows PC. Below I'll break down what they do.
- autoMemoryReclaim
- This setting is used to control the automatic reclamation of memory from WSL instances.
gradual
: Specifies that memory should be reclaimed gradually, which helps in preventing performance issues due to sudden memory reclamation.- sparseVhd
- This setting controls whether the virtual hard disks (VHDs) used by WSL instances are created as sparse files.
true
: Specifies that the VHD should be created as a sparse file.
Installing Ubuntu 24.04.
- In a Powershell Shell, we will need to copy that command to install Ubuntu 24.04.
wsl --install -d Ubuntu-24.04
user: devops
pass: somdevops
User and Pass do not need to be that this is just an example of when it asks you.
Configuration of Ubuntu
After You're dropped into Ubuntu. We're going to do some tweaks to the Quality of life and make WSL a little more fun.
These next steps should be performed as root. That can be achieved by using the command below.
sudo -i
Update Script
- Go ahead and copy this into the terminal.
touch /usr/local/bin/update && chmod +x /usr/local/bin/update
cat <<EOF >/usr/local/bin/update
sudo apt update
sudo apt upgrade
EOF
/usr/local/bin
which is specifically used to store executable files (binaries) that are intended to be accessible by all users on the system but are not part of the core operating system. This Specific script just does a system update with one command instead of two.
WSL config file
touch /etc/wsl.conf
cat <<EOF >/etc/wsl.conf
[boot]
systemd=true
[automount]
root = /
options = "metadata,dmask=022,fmask=033"
[user]
default=devops
EOF
This config file just setups wsl to act more like a native Linux system. But Also specifies the default user.
Epilogue
Well, Ladies and Gents. This is the end. In this post, we Installed WSL and its dependencies. Installed Ubuntu and made some tweaks. You now have a work Linux env inside Windows and you can do a whole lot with it. So go out there and have some fun.