Getting started with WSL 2

Dien Bui
4 min readJun 25, 2020

--

In this blog post, I will combine and organize information from multiple sources I have read so far and from my own experience to show you how to setup and run WSL 2 on your Windows 10 with speed. In addition, I will show you how to setup Docker on WSL 2.

I’m sure that if you find this post then you might have heard of the term WSL and the number 2 after that ;) . I will not go into details on WSL and WSL 2 in this post, so if you want to find out more before “getting your hands dirty”, you can refer to Microsoft’s official documentation for details.

IMPORTANT!!!

  • You must have at least Windows 10 version 2004 and OS build 19xxxxx / you have installed Windows 10 May 2020 Update.
  • You can open Start Menu, type About your PC and scroll down to Windows specifications to verify those numbers.

Enable WSL

  • Open Start Menu and go to Turn Windows features on or off.
  • Ensure Windows Subsystem for Linux and Virtual Machine Platform are checked.
  • You will need to restart Windows for these features to be enabled.
  • Install latest WSL 2 Linux kernel https://docs.microsoft.com/en-gb/windows/wsl/wsl2-kernel
  • Open Powershell and type wsl --set-default-version 2 . This ensures all Linux distribution will be installed using WSL 2 by default.
  • (Nice-to-have) For better command-line experience in the later steps, install Windows Terminal from Microsoft from Microsoft Store. I plan to publish another blog post about setting up Windows Terminal, so please stay tune ;)
  • You will see a message as below and follow the link to install additional package.
  • Once finished installing packages, go back to Powershell and run the command above again.

Install Linux distribution

At this point, WSL 2 is setup and enabled on your Windows. However we don’t have any Linux distribution installed yet. Microsoft and partners have published many distributions on the Microsoft Store such as Ubuntu, Fedora and Kali Linux. I will choose Ubuntu for demonstration in the upcoming steps

  • Go to Microsoft Store, search Ubuntu then install it
  • Once finished, open Ubuntu and wait for setup process to complete
  • Type in your username and password

Voila! Now you have Ubuntu running and you can start customizing it with oh-my-zsh or head straight to install your favorite packages with apt-get or clone your GitHub repos using Git CLI….

If you wonder if you can install Ubuntu GUI apps on WSL 2 and use them on native Ubuntu, then my answer to you is No (for now). Microsoft already has a roadmap to support Linux GUI applications and even GPU such as NVIDIA CUDA, which is what data engineers/data scientists out there are dreaming of so as to be able to run Tensorflow or similar tools right on WSL :) .

Bonus: Install Docker

If you are a software, devops or data engineer, you definitely have heard or worked with Docker, the most popular containerization tool. Since WSL 2 allows running a full Linux kernel on Windows, you can definitely install and run Docker containers on it.

You can either install using commands from the Docker docs or install Docker desktop. I highly recommend Docker desktop because Microsoft and Docker Inc have cooperated to bring optimized Docker on WSL. You can simple go here and download it.

Once finished you can head straight to WSL 2 and check if it is running using docker version . WSL 2 brings a huge performance improvement compared to WSL 1 so you can run multiple containers with volumes mounting like on native Ubuntu without worrying about the performance like on Docker for Mac.

How about localhost , do I have you setup anything else to open browser on Windows and type localhost:3000? You don’t have to do anything at all, just start up your Express.js server, for example, running on port 3000 on WSL 2 and go ahead with localhost:3000 on your browser.

Happy coding guys and have fun exploring WSL 2. Stay tune for more posts ;) .

--

--

Dien Bui

Backend, data and cloud computing enthusiast | Power of open-source and sharing believer | GitHub: https://github.com/joebui