Introduce and install WSL on Windows

Tram Ho

Introducing Windows Subsystem for Linux

WSL (Windows Subsystem for Linux) is a feature available on Windows x64 (from Windows 10, version 1607 and on Windows Server 2019), it allows running Linux operating system (GNU / Linux) on Windows. With WSL you can run commands and applications directly from the Windows command line without having to worry about creating / managing virtual machines like before. Specifically, some notes that Microsoft lists can do with WSL:

  • Choose to use Linux distro from Microsoft Store: There are currently very light Linux Distros on the Store that can be used on Ubuntu, Debian …
  • Runs from command line linux commands like ls, grep, sed … or any 64 bit binary program (ELF-64) of Linux
  • Run tools like: vim, emacs …; programming languages ​​like NodeJS, JavaScript, C / C ++, C # …, services like MySQL, Apache, lighthttpd …
  • It is possible to install packages from that Distro’s package manager (like the apt command on Ubuntu).
  • From Windows can run Linux applications (command line)
  • From Linux it is possible to call Windows applications

Install Windows Subsystem for Linux

Make sure your system is Windows 10 (64 bit, version 1607) onwards or Windows Server 2019, check with the command in PowerShell (PS):

In addition, you need to activate the CPU virtualization support mode (CPU Virtualization), you activate by accessing the machine’s BIOS, depending on the type of motherboard where the activation is different.

To install, open PS (PowserShell) as Administrator (right-click on the icon of the window – start, then select Windows PowerShell (admin)), then execute the command in PS

After it activates, press Y to answer the question as shown above to restart the device. Restart your computer, enter the command line, and check the list of installed distros (linux version):

At this time, there is no linux version installed, registered – so notice as above, it requires you to visit Microsoft Store under the link https://aka.ms/wslstore , to find and download Distro Linux want to install

Access the Store by following the link above, in the list of Distro Linux install options which you want to use, for example, if you select Ubuntu, select the Ubuntu icon

Click Install to download and install Ubuntu for WSL

Once downloaded, choose to run Ubuntu from the Windows Start menu, to start registering with WSL

The process of installing Ubuntu takes place, then it will ask you to set up a user and password for this Linux, enter the username and password you set:

You have already started running Ubuntu in Windows, at the Ubuntu command line, after each time running Ubuntu from the Start menu you will be directed to this command line. Now you have started to be able to execute Ubuntu Linux commands on Windows.

Now if you have an exit command or close the window then Ubuntu will stop

Now from PS you can have several commands to check:

Tips

Install and use Windows Terminal, a new command line tool for Windows – hopefully a good replacement for PowserShell and Cmd with features like tabs, theme changes …

Update Ubuntu: to update packages in Ubuntu, type wsl to enter Ubuntu, then execute the command

Interaction between Windows and Linux

Windows calls the Linux command

The system currently has WSL, which registers a default Distro as Ubuntu. Now at the Windows command line interface (CMD, PowerShell, or Windows Terminal) – you can call and execute commands contained in Ubuntu with the syntax

For example, in Ubuntu – as it is known that the text editor is nano, you can now use it on Windows – like editing a 1.txt file in the current directory:

The path of the C:/ drive on Windows is mounted and Linux under the /mnt/c/ , so to access the C:Usersxuanthulab1.txt of Windows, the corresponding on Linux is /mnt/c/Users/xuanthulab/1.txt

Alternatively, you can browse the Ubuntu file system from File Explore, located at \wsl$Ubuntu

Linux calls Windows command

In the opposite direction, if you are in Linux (enter with the wsl command), then you can call Windows programs, such as nodepad.exe, explorer.exe …

Updated to WSL2

Microsoft introduces better WSL2, for example, fully supports the Linux kernel, will update in the next Windows version, Windows Feature May 2020 Update Version 2004, WSL2 takes effect from the Windows 10 build: Windows Builds 18917

At this point, if you enable the Windows Insider Program subscription (access Update and Setting – Select Windows Insider Program to register), you will receive preview updates of Windows that support the WSL2 distro linux wsl Register Windows Insider Program – get preview updates

After updating, go to wsl2-kernel, download the WSL2 Linux kernel update package, then run to update, then run the following command to switch the default WSL2

Check which version of Distro is running

Convert Distro from version 1 to version 2: convert ubuntu for example

Source: https://xuanthulab.net/gioi-thieu-va-cai-dat-wsl-tren-windows.html

Share the news now

Source : Viblo