Use Linux on Windows 10 (WSL2)

With Windows Subsystem for Linux 2 (WSL2) on Windows 10, you can play Linux on Windows 10 very easily.

How to Install

Requirements

Enable "Windows Subsystem for Linux"

Open powershell as administrator and do the following:

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

Enabling "Virtual Machine Platform"

Open powershell as administrator and do the following: You will be asked if you want to restart your PC, so enter Y. The PC will restart automatically.

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all

Installing the Linux kernel for WSL2

Download and install the Linux kernel for WSL2 from the Update WSL 2 Linux Kernel (https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel) page.

Set default to WSL2

Set to use WSL2 by default when installing a Linux distribution. Open powershell and do the following:

wsl --set-default-version 2

Install a Linux distribution

  1. Start Microsoft Store and search for distributions such as Ubuntu Besides Ubuntu, there are several types such as Debian and SLES. If you want to install a specific version of Ubuntu, you should install the one with the version (Ubuntu 20.04 LTS, etc.). There seems to be a change in the version of Ubuntu depending on when it is installed.

image.png 2. Click the "Get" button to install Ubuntu 3. After the installation is complete, click "Start" to start Ubuntu! image.png 4. Set the Ubuntu user ID and password at the first startup, and the installation is completed. The user name you enter here has nothing to do with your Windows user name. If you need root privileges, you can run it with sudo. If you have forgotten your password, see Forgot Password. image.png

How to use

Start from the start menu

The installed Linux distribution can be started from the start menu in the same way as a normal application. Start while logged in as the created user.

Access from Windows Terminal

In Windows Terminal, the WSL2 profile is automatically registered, so you can easily access it. So recommended. You can install it from the Microsoft Store, so if you are interested, give it a try. image.png

File sharing between Windows and Linux

Accessing files on Windows from Linux

Windows C drive is mounted on Linux / mnt / c. You can access files on Windows by accessing / mnt / c.

Accessing files on Linux from Windows

You can access files on Linux with \\ wsl $ \ [distribution name]. If you are using Ubuntu, access it with \\ wsl $ \ Ubuntu.

Time shift problem

I've been using it for a while and noticed that the Ubuntu time on WSL2 is shifting quite a bit. Apparently, Ubuntu isn't syncing with the Note PC when it wakes up from sleep. It seems to be a known issue and has not been fixed yet. (WSL2 date incorrect after waking from sleep) As a workaround, use sudo hwclock -s to forcibly synchronize the time or use wsl --shutdown to stop WSL2 and then start it. For the time being, I try to execute sudo hwclock -s every time I log in as shown below.

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
%sudo   ALL=(ALL) NOPASSWD: /usr/sbin/hwclock -s  #Add this line
# sync HW clock
sudo hwclock -s

How to Uninstall Installed Linux distributions can be uninstalled from Add or Remove Programs just like regular applications.

Other

You can browse the list of installed distributions, uninstall, etc. with the wsl command from the command prompt.

C:\>wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

Link

Recommended Posts

Use Linux on Windows 10 (WSL2)
Linux (WSL) on Windows
WSL2 ~ Linux on Windows ~ (Part 1: Introduction)
Install wsl2 and master linux on windows
Use pyvenv on Windows
Use Ansible on Windows
Use QuTiP on Windows
Organize files on Windows with Linux commands-using WSL-
Use Github Desktop on Linux
Use Windows 10 fonts with WSL
Linux on Windows -1-: debian introduction
Use sshpass on Amazon linux2
Use Python on Windows (PyCharm)
Linux environment construction (on WSL environment)
Use host.docker.internal on linux (docker-compose required)
How to use Dataiku on Windows
Create a Linux environment on Windows 10
Use Tensorflow 2.1.0 with Anaconda on Windows 10!
Use Chrome Remote Desktop on Linux
pykintone on Windows Subsystem for Linux
Use Linux commands on Android devices
[UE4] Build DedicatedServer on Windows and Linux
Python on Windows
Why use linux
Use Numpy, Scipy, scikit-learn on Amazon Linux
How to use Google Assistant on Windows 10
WSL2 (Windows Subsystem for Linux) installation procedure
Create a Linux virtual machine on Windows
Open a ZIP created on Windows in Linux
Cross-compile windows version from nim on arch | linux
[Windows] Memo to use Keras on GPU [Tensorflow-GPU]
Daemonizing processes on Linux
Install python on WSL
jblas on Arch Linux
Pylint on Windows Atom
NAT router on Linux
Anaconda on Windows Terminal
Install Anaconda on Windows 10
python basic on windows ②
Install python on windows
Install pycuda on Windows10
Build TensorFlow on Windows
Monitor traffic on Linux
Try FEniCS on Windows!
Build XGBoost on Windows
Update vscode on linux
Try Poerty on Windows
Try NeosVR on Linux
Install Chainer 1.5.0 on Windows
Check capacity on Linux
LiveUSB creation on Linux
Linux operation on Win10
When I tried to use Python on WSL (windows subsystem for linux), it got stuck in Jupyter (solved)
Run Kali Linux on Windows with GUI (without VirtualBox)
Problems with windows python being called on pipenv on WSL
How to use C216 Audio Controller on Arch Linux
Preparing to use Ansible on an existing Linux server
I want to use OpenJDK 11 on Ubuntu Linux 18.04 LTS / 18.10
A story about a Linux beginner putting Linux on a Windows tablet
[Tips] How to use iPhone as webcam on Linux
Cross development environment (developing programs for windows on linux)