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

comments powered by Disqus
All rights reserved,未經允許不得隨意轉載
Built with Hugo
Theme Stack designed by Jimmy