WSL2: Linux on Windows 10

With this post we are talk about WSL2, Linux on Windows, Windows Terminal and more

Are you looking to run a terminal session for your WSL2 Linux operating system, use Linux on Windows or just want to play around? Continue reading!

For this post we are using the following software:

  • Windows 10, version 20H2
  • Ubuntu 20.04 LTS, version 2004.2020.812.0
  • Windows Terminal, version 1.4.3243.0
  • Docker Desktop, version 3.0.4 with WSL 2

What is WSL2

WSL stands for Window Subsystem for Linux, so it can run Linux on directly Windows. Yes we could do this already with VMWare or Virtualbox, but with support of WSL2, we can run it without the traditional overhead of a virtual machine or dualboot.

With the release of WSL 2, they have increased the performance of file system and added support of full system call compatibility.

With WSL2 you can:

  • Choose a GNU / Linux distribution from the Microsoft Store.
  • Run command-line tools such as grep, vim, curl or any other Linux command.
  • Invoke Windows applications using a Unix-like command-line shell.
  • Invoke GNU/Linux applications on Windows.

Install Windows Subsystem for Linux

The developers at Microsoft already created a tutorial how to install WSL2, so this part will not be discussed here.
Follow the document of Microsoft.

During the tutorial of Microsoft the following commands are executed.

# Install WSL
wsl --install

# Enable Windows Subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

# Enable Virtual Machine features, required for WSL2
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

# Set WSL version 2 as default version
wsl --set-default-version 2
        

Download Ubuntu on Windows

At this stage we have installed WSL2 on Windows, next step is to install a Linux distribution of your choice. For this post we are installing and configuring Ubuntu 20.04 LTS (Long-Term Support). Go to the Microsoft Store and search for Ubuntu. Good to now that you can download and install items from the store without an account.

After the installation, of a few minutes, a console will be launched to enter a username and password, make sure to write down those credentials. These credentials will give you access to the Linux distribution.

Linux Terminal in Windows 10

After installing a Linux distribution, we can download and install the Windows Terminal, this can also be installed direct from the Microsoft Store.

When Windows Terminal is launched, it starts in a PowerShell window. In order to open a Linux distribution, Ubuntu in our case, press the arrow down in the title bar. Click the console environment you want, so there you have it. You have a terminal session for your WSL2 Linux operating system.

WSL2 with Docker

After installing and enabling WSL2, you should ensure that Docker Desktop is configured to use the WSL2 back-end.

To configure Docker with WSL2, we need to set 2 different variable:

  • Docker -> Settings -> General: Enable option Use the WSL2 based engine
  • Docker -> Settings -> Resources-> WSL integration: Enable specific distros which will run with WSL2

WSL commands

WSL is a commandline tool, here you can find the most useful commands

List all distributions with detailed information:

wsl --list --verbose
wsl -l -v

Set WSL version 2 as default version:

wsl --set-default-version 2
        

Set a distribution to be backed by either version of WSL:

wsl --set-version [distribution name] [versionNumber]
        

With this post you have configured WSL2 and enabled a Linux terminal on Windows. If you have any questions or feedback, we like to hear it in the comments!

Thank you for reading this article, If you liked the article, help others find this article by sharing it.

Reacties

Populaire posts van deze blog

Android-x86 virtual machine configuration tips

Android and SonarQube with code coverage

Setup SonarQube with Docker