Monday, November 12, 2018

Windows Subsystem for Linux, the best way to learn Linux on Windows

Earlier this year, Microsoft released the Windows Subsystem for Linux (WSL). WSL lets developers run the GNU/Linux shell environment on a Windows 10 PC, including most command-line tools, utilities and some services, directly from source repos without the overhead of a virtual machine.

WSL is also the best way to learn Linux on Windows!

About WSL

Currently WSL supports Ubuntu, Debian, Suse and Kali distributions and can:
  • run bash shell scripts 
  • run GNU/Linux command-line applications including: vim, emacs, tmux
  • run programming languages like Javascript/Node.js, Ruby, Python, C/C++, C# & F#, Rust, Go, etc.
  • run background services like sshd, MySQL, Apache, lighttpd;
  • install additional software using own GNU/Linux distribution package manager.
  • invoke Windows applications.
  • access your Windows filesystem

Installing WSL on Windows 10

Installing WSL is covered by Microsoft on this article and is as easy is two steps. Let's take a quick look.

Step 1 - Run a Powershell Command

To install WSL on your Windows PC, it will be necessary to run PowerShell as Administrator (shift + right-click) and run the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux 
After the installation ends, restart your PC.

Step 2 - Install WSL

After the PowerShell module is installed, I recommend installing WSL through the Windows Store. To open the Windows Store on your Windows 10, click:
Start -> Type Store -> Click on the Windows Store:
Then type "Linux" on the search box and you should get something similar results to this:

To install any of those Distros, just click on the thumbnail, accept the terms and click Get!  Windows will download and install WSL for you

Running WSL

After installation started, you will be prompted to enter your username and password. After done, you'll get a cool Linux terminal to start playing with. You can even have multiple Distros installed on your Windows 10 machine.

On mine, I installed Debian and Ubuntu. Here's the last bit of the Debian installation :

Using the Terminal

After installation is done and you entered your credentials, potential next questions would be:
  • Where are my files? 
  • Do I have internet?
  • How do I install software?

Let's review those.

Accessing my Windows Files

It's all there on the /mnt/c mount point. To verify on yours type mount on the command prompt and look for C: on it. That's where your windows files should be.

Which I can list contents with ls:

Accessing the Internet

The WSL instance should have working internet out of the box. Testing the internet is as simple as doing a ping to Google:

If you're using Ubuntu, you can also verify your network info with ifconfig:

Installing Software

On Debian-based systems (Ubuntu included), installation is done by the apt command. For example, searching for a package is as simple as:
Then, to install Ruby on the Ubuntu subsystem is just running the command below as root:
$ apt-get install ruby-full

Other Tasks

Now that you understood how to locate your PC files, validated your access to the internet and installed some software, I'd recommend that you:

Conclusion

So you have the WSL installed on your machine and a Linux terminal ready to starting interacting with. Now what?

I would suggest that you learn basic system commands (ls, cp, man, rm, ps, etc), understand the filesystem, learn to manage software, understand the networking stack and review how to perform certain administrative tasks on the terminal.

The Linux terminal is perfect for users who want to learn Linux and to those who spent a lot of time on Windows but need access to a Linux terminal.

And who knows? Maybe you too realize that Linux is awesome and decide to install it as your main OS? =)

See Also

Thank You, Fedora
Building and Running Asp.Net Core apps on Linux
Installing Docker on Linux
Running RavenDB on Docker

For other Linux posts on this blog, please click here.

Further Reading

Some interesting articles to explore on this topic could be:
    WSL - FAQ
    WSL - Installing
    WSL - Documentation
    WSL - Command Line Reference
    An A-Z of Linux – 40 Essential Commands You Should Know
    Linux Command Line tips that every Linux user should know
    Must-Know Linux Commands For New Users