Ever wondered ?! if there existed a way where you could easily use the Linux CLI and bash scripting natively inside Windows without the hassle of making a heavy virtual machine or worse going through the godforsaken process of partitioning your drive and dual booting your system?
Well! No worries WSL to your rescue.
So...what exactly is WSL you may ask?
The Windows Subsystem for Linux or WSL or C:\Windows\System32\wsl.exe is a simple executable that allows you to install a Linux distribution as an app from the Windows store. Windows WSL is a great solution for developers to natively work with GNU/Linux Environment including CLI tools, utilities, and applications on Windows OS without the need for any VMware or dual boot. This saves system resources like Memory, CPU and Storage without affecting performance.
There are two versions of WSL: WSL 1, which runs Linux applications as (special) Windows processes and WSL 2, which runs a lightweight virtual machine on the Hyper-V included in Windows. Both, WSL 1 and WSL 2 are different than the heavyweight virtual machines that you can run using “normal VMs” on Hyper-V, VMWare and VirtualBox.
WSL 2 is now the default and the specific scenarios or exceptions that may warrant switching your installed Linux distribution to the earlier WSL 1 architecture are out of the scope of this article.
A little brief about WSL 2
WSL 2 is a major overhaul of the underlying architecture and uses virtualization technology and a Linux kernel. WSL 2 provides the benefits of WSL 1, including seamless integration between Windows and Linux, fast boot times, a small resource footprint, and requires no VM configuration or management. While WSL 2 does use a VM, it is managed and run behind the scenes, leaving you with the same user experience as WSL 1. The Linux kernel in WSL 2 is built by Microsoft from the latest stable branch. This kernel has been specially tuned for WSL 2, optimizing for size and performance to provide an amazing Linux experience on Windows. The kernel is serviced by Windows updates, which means you will get the latest security fixes and kernel improvements without needing to manage it yourself.
Enough of the nerdy stuff: Let's get started
To get started open Terminal on your Windows system. Type this command
wsl --list --online
On running this command you'll be greeted with all the Linux distros that you can install currently on wsl.
Just copy the name of the distro that you want to install and run this command, we here have chosen to install Ubuntu you can go ahead with any of your preferences.
wsl --install Ubuntu
You'll be asked to set up your Unix username and password after installation, to force the distro to accept your chosen username use the --force-badname command after entering the username of your choice.
Although you could have done this installation via the Microsoft store, doing it via the command line is a good practice.
Let's test our new distro
Open the Windows start menu.
Type Ubuntu and press enter
The Ubuntu command line will open
Now type the command echo "hello world"
echo "hello world"
Now we know our WSL instance is working, if it does not work try restarting you system. Let's look at something interesting.
Because this WSL Ubuntu instance is installed natively inside Windows you can also directly access your Windows files and folders from the Ubuntu instance itself.
Type the command 'cd /mnt/c', to enter the c:\ drive of windows.
cd /mnt/c
Now type the 'sudo ls' command to list all the files inside the c:\ drive
sudo ls
From here you can navigate accordingly to your desired files and folder using the 'cd' command.
Whether it be writing your own bash scripts or setting up a secure shell (SSH) to your remote servers, you can do it all with WSL, possibilities are endless. It’s worth using if you don’t have a machine dedicated to Linux. It beats dual-booting, and for a lot of things it beats a virtual machine since it can easily access your filesystem.
Now go ahead, enjoy and explore your new WSL instance!