David Dong

David Dong

Java/C/C#/Python

Java/C/C#/Python

POST

Some notes for WSL

Recently I’m using WSL(Window Subsystem for Linux) for program development. This article presents some short notes for the WSL installation and usage.

What is WSL?

Below is the official introduction of WSL, I copied it here as a startup.

The Windows Subsystem for Linux lets developers run a GNU/Linux environment – including most command-line tools, utilities, and applications – directly on Windows, unmodified, without the overhead of a virtual machine.
You can:

  • Choose your favorite GNU/Linux distributions from the Microsoft Store.
  • Run common command-line tools such as grep, sed, awk, or other ELF-64 binaries.
  • Run Bash shell scripts and GNU/Linux command-line applications including:
    • Tools: vim, emacs, tmux.
    • Languages: NodeJS, Javascript, Python, Ruby, C/C++, C# & F#, Rust, Go, etc.
    • Services: SSHD, MySQL, Apache, Lighttpd, MongoDB, PostgreSQL.
  • Install additional software using own GNU/Linux distribution package manager.
  • Invoke Windows applications using a Unix-like command-line shell.
  • Invoke GNU/Linux applications on Windows.

How to install WSL?

You can refer to installation guidance, the introduction is detailed. You can complete the installation of WSL1 and WSL2 easily just by following the guidance step by step.

How to use?

On the above procedure, you will be requested to choose one Linux OS to install, the choice has

  • Ubuntu 16.04 LTS
  • Ubuntu 18.04 LTS
  • openSUSE Leap 15.1
  • SUSE Linux Enterprise Server 12 SP5
  • SUSE Linux Enterprise Server 15 SP1
  • Kali Linux
  • Debian GNU/Linux
  • Fedora Remix for WSL
  • Pengwin
  • Pengwin Enterprise
  • Alpine WSL
  • After installing the Linux OS at the Windows store.

I choose Ubuntu 16.04 LTS as my Linux system and installed it. The system installation is quite faster than installing on a virtual machine from my own experience. During the process, no need to input any information. After installation, just open the CMD console and input ubuntu, you will run Ubuntu on your Windows system.

Here are some useful tips.

use wslconfig command

In the CMD console, input below command to set the default Linux system if you have multiple.

wslconfig /setdefault <DistributionName>

use below command to uninstall the specified Linux system.

wslconfig /unregister <DistributionName>

use below command to check the available system on you computer.

wslconfig /list

The output of my computer is

C:\WINDOWS\System32>wslconfig /list
Windows Subsystem for Linux Distributions:
Ubuntu-16.04 (Default)

set the default user

If you want to change the user, you can use the below command For example, you want to set the default user as root on the Ubuntu.

ubuntu config --default-user root

WSL file system and local file system access

  • Access local files in the WSL system. It is easy to access the local file in the WSL system, the local file system is mounted at the /mnt folder. There are c, d, e, and other folders in the /mnt directory, which respectively represent the local C disk, D disk, and E disk. You can directly cd them to the corresponding path.

  • Access WSL file in the local system. It is not recommended to do so, at least do not try to modify any file externally. Otherwise, it might cause some problems.

Actually, the root directory of WSL can be found at local system path.

C:\Users\XXXX\AppData\Local\Packages
\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs

Linux

You may also like

further reading