If you love Linux OS and its ecosystem but you always find yourself with a Windows OS and virtualization or dual boot never gave you the full experience or performance, Microsoft brought the best of both worlds. We were very excited when Microsoft announced WSL2 in 2019. And we believe it to be the best web development setup.
WSL stands for Windows Subsystem for Linux, which is a compatibility layer for native Linux environments within windows. Its first version WSL1 was announced in 2016, but it had several performance problems because it translated Linux system calls to Windows equivalents. WSL2 on the other hand is the entire native Linux kernel running on Windows at full performance. WSL2 uses Hyper-V virtual machine technology so Linux compatibility is excellent and file access is up to 20x faster than before.
Of course, you first need to have a Windows OS running on your machine and it has to be on the 2004 version or higher to be able to use WSL2. To check if your machine is meeting the requirements simply press
start and enter
If you have an older version you can update to a newer version with
Windows updateassitant just run it by pressing
start and enter
Windows updateassitant, it will walk you through it. If it's not available on your machine you can install it from Microsoft software download.
Now that your Windows is all set, let’s enable WSL on your system. The very simple way is to open PowerShell terminal as an administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
Keep the same terminal to now enable the virtualization by running:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Now you need to restart the machine. On your machine is on again open a PowerShell terminal as an administrator and run:
wsl --set-default-version 2
This will set your WSL 2 as the default version.
Install a Linux distribution
Now you need to install a Linux distribution of your choice. Open the Microsoft Store and select your favorite Linux distribution. We use Ubuntu but feel free to pick your distribution.
Once the installation is complete, you can check the installation from PowerShell terminal by executing:
wsl --list --verbose
And you should see Ubuntu listed as follow:
You should also be able to run the Ubuntu prompt for the Ubuntu bash:
When you run it for the first time you will be asked to enter the password for the admin user. Make sure to remember the password or noted it somewhere.
We love using Windows Terminal, which is available on Microsoft Store, Windows Terminal will automatically add your WSL2 Linux distributions and offers a highly configurable range of options including tabs, split views, themes, and so on, you can check their GitHub repository for more options.
Before we walk you through the installation of docker. Let’s first briefly understand docker and why we use it.
Wikipedia defines Docker as:
an open-source project that automates the deployment of software applications inside containers by providing an additional layer of abstraction and automation of OS-level virtualization on Linux.
From a practical standpoint, docker is a way to package software so it can run on any hardware, there are three things components that you need to know when working with docker:
dockerfile: is a blueprint for building a docker image (the configuration file)
docker image: is a template for running docker containers
container: is a running process of the image
In the case of a web application with its dependencies (programming language, web server, database ..), we need to run on a machine with the dependencies of their corresponding versions. It might work on a machine but it might not work on another machine because of a slightly different version of one of the technologies used in that web application. The whole point of docker is to solve this kind of portability problem by reproducing the same environments. Developers can define the environments by configuring the dockerfile that is saved as an immutable snapshot or image that can be uploaded to the cloud both in private and public registries and at any point the same environment can be reproduced using these images by pulling them down to create a container which is just a running process of that image.
The best way to understand docker is to use it, so let’s first download it and install it.
We highly recommend using the docker desktop application if you’re on windows or mac. It installs everything you need for the command line and also gives you a GUI where you can inspect your running containers.
To install docker desktop application simply go to docker website and install the executable installer. Once docker installed run the following command to get the version of docker installed and to verify the installation.
> docker -v
Make sure to activate the WSL2 and to enable the integration with your installed distribution, in our case it’s Ubuntu.
If you use Visual code as an IDE we recommend installing The Remote WSL extension that lets you use VS Code in WSL just as you would from Windows.
We also recommend the docker extension for the VS code, it will give you language support when writing your dockerfiles and can also link up to remote registries and a bunch of other stuff.