قالب وردپرس درنا توس
Home / Tips and Tricks / What Is The Windows Subsystem For Linux (WSL) And How Do You Use It? – CloudSavvy IT

What Is The Windows Subsystem For Linux (WSL) And How Do You Use It? – CloudSavvy IT



Windows Subsystem For Linux (WSL) is a tool from Microsoft to run Linux natively on Windows. It is designed to be a seamless experience, essentially offering a full Linux shell that can communicate with your Windows file system.

Not just a virtual machine

Let’s start with what WSL isn’t: it’s not a full Linux desktop experience that you could get by running Ubuntu in VirtualBox, for example. It technically uses virtualization for performance reasons, but it̵

7;s very different from running a full VM. It’s all managed for you, just providing you with a simple shell and environment to do your job and use familiar bash commands like git ssh, and any other tools included with the chosen distribution.

Basically, WSL allows you to install a full Linux distribution as an app from the app store. You can simply download, install and have Ubuntu (or the distro of your choice) available as an app you can launch, or as a profile in your terminal to use alongside CMD or Powershell.

While the simplest explanation is that it “lets you run bash on Windows,” it’s more than just a shell; you can install programs with apt and modify it as a regular Linux instance.

WSL aims to give developers and bash veterans the Linux shell experience, despite having to use Windows as the primary operating system. It offers the best of both worlds by allowing you to run Windows apps, such as Visual Studio, alongside a Linux shell for easier command line access.

Microsoft offers two versions of WSL: version 1 and version 2. WSL 2 uses a virtual machine and uses a full Linux kernel built and shipped with Windows. WSL 1 is older, and generally a lot slower, but performs better when working with different file systems, eg accessing Windows files from Linux, and vice versa. We recommend WSL 2 for most operations as it is faster and works much better with tools such as Docker.

Set up WSL

WSL is an optional Windows feature so you must enable it. Open Powershell as Administrator from the start menu:

Then enable it:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

You must restart your machine for the changes to take effect. After that, you can open the Windows Store and search for “WSL”, which will list the available distributions:

The first time you run it, you will be prompted to set your username and password for the instance. These are for Linux only and do not have to match your Windows password at all.

The first one you install should be set as your default, but if you install several, you will have to set the default manually. You can manage WSL through the wsl command in Powershell. For example, a list of all currently installed versions:

wsl --list

Then you can set up your default WSL distro with the following command, which can also be used to switch between WSL 1 and 2 ″

wsl --set-version Ubuntu-20.04 2

You can also set a preferred WSL version (1 vs. 2) for all future installations:

wsl --set-default-version 2

Using WSL

You can access WSL in several ways. The easiest way is to just press Windows and type “wsl”, which will run automatically wsl.exe and open your default distro.

However, this is just a standard terminal window; if you’re using Microsoft’s new Terminal app, which we highly recommend, your WSL versions can be accessed from a drop-down menu (next to any SSH profiles you may have set up):

If you want to create a new profile, the configuration for it is the following:

{
    "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
    "hidden": false,
    "name": "Ubuntu",
    "source": "Windows.Terminal.Wsl",
    "fontFace": "RobotoMono Nerd Font",
    "fontSize" : 10,
    "cursorColor" : "#FFFFFF",
    "cursorShape" : "bar",
    "fontFace" : "RobotoMono Nerd Font",
    "acrylicOpacity" : 0.75,
    "closeOnExit" : true,
    "colorScheme" : "Campbell"
},

A note on file systems

Your Linux file system is mounted on /, as usual. Windows is located on /mnt/c/, or whatever drive letter is your default (additional drives will also be mounted).

Since this is all virtual, your Linux files will of course be stored on the disk itself. For WSL 1 these are stored with a simple folder. However, WSL 2 changes things and stores files as a virtual hard drive, or VHDX.

You can find these images in the following path, and while they can be mounted while the distro is not registered, we don’t recommend messing with them from the Windows side.

%USERPROFILE%AppDataLocalPackagesCanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndgscLocalState

Source link