Featured image of post Run the Ubuntu on the Windows by using WSL2

Run the Ubuntu on the Windows by using WSL2

Run the Ubuntu on the Windows by using WSL2, You can easily edit or change any files on the windows and run on the Linux environment. You never have to deal with the different platform issue after deploy your code on the production. You can also run any Linux based software by using wsl

Photo by Gabriel Heinzer on Unsplash

You can use WSL to run the Linux-based program on the Windows

WSL2 Version

If your Windows 10 has been upgraded to the 20H1/20H2 or higher version, then the default version of the WSL will be WSL2

Enable Hyper-V

You can go to the Control Pannel or search the programs keyword, then click Add or remove programs

Add or remove programs

Click the Programs and Features on the right side.

Programs and Features

Click Turn Windows features on or of to open the Windows Features window

Turn Windows features on or of

And enable all the Hyper-V options.

Enable Hyper-V

Active WSL

Run the PowerShell as an administrator, then run the following 2 commands to activate wsl

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

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

Restart windows after run the active wsl commands to active WSL

Confirm WSL Active Status

Go back to the original Windows Features window to confirm if the following 2 options are all enabled

  • Virtual Machine Platform
  • Windows Subsystem for Linux

Confirm WSL Active Status

Change WSL Version

Make sure your WSL version is set to 2

wsl --set-default-version 2

Download the Ubuntu from the Microsoft Store

Hint: You can download any version of the Linux that you want, but here is using Ubuntu 20.04 LTS

Open Microsoft Store the search Ubuntu to download the Ubuntu system

Download the Ubuntu from the Microsoft Store

After install fininsh, then open the Ubuntu, and try to setup you account & password on the Ubuntu. Then you can close this window.

Download the Ubuntu from the Microsoft Store Download the Ubuntu from the Microsoft Store

Show available Linux version from the WSL

Run the wsl -l can show all of the available Linux version

wsl -l

But I only install 1 version of Linux, so here is only 1 version that shows on the screen.

If you install multi-version of Linux, it will show all of the Linux versions right here.

Show available Linux version from the WSL

Use WSL to connect specific Linux version

wsl -d Linux System Version Name

wsl -d Ubuntu-20.04

Run the wsl -d to access the specific Linux version.

Then you will see all of the Linux files are all synchronized with the Windows on the /mnt path

So you can edit or change anything you want on the Windows environment, then execute it on the Linux environment

Use WSL to connect specific Linux version

WSL Commands

Commands Description
wsl -h Show all of the wsl commands
wsl -l Show all of the available Linux version
wsl -d Connect specific Linux version

Reference

Donate KJ 贊助作者喝咖啡

如果這篇文章對你有幫助的話,可以透過下面支付方式贊助作者喝咖啡,如果有什麼建議或想說的話可以贊助並留言給我
If this article has been helpful to you, you can support the author by treating them to a coffee through the payment options below. If you have any suggestions or comments, feel free to sponsor and leave a message for me!
方式 Method 贊助 Donate
PayPal https://paypal.me/kejyun
綠界 ECPay https://p.ecpay.com.tw/AC218F1
歐付寶 OPay https://payment.opay.tw/Broadcaster/Donate/BD2BD896029F2155041C8C8FAED3A6F8
All rights reserved,未經允許不得隨意轉載
Built with Hugo
Theme Stack designed by Jimmy