Monday, November 12, 2018

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

Want to learn Linux but don't know how/where to start? WSL may be a good option.
In 2018, Microsoft released the Windows Subsystem for Linux (WSL). WSL lets developers run the GNU/Linux shell on a Windows 10 PC, a very convenient way to access the beloved tools, utilities and services Linux offers without the overhead of a VM.
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, Golang, Rust, C/C++, C# & F#, etc.
  • run background services like ssh shells, 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.

Step 1 - Run a Powershell Command

On your Windows PC, you will need to run this PowerShell script as Administrator (shift + right-click):
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows -Subsystem-Linux
After the installation ends, restart your PC.

Step 2 - Install WSL from the Windows Store

After the reboot, WSL can be installed 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:

Click on the icon, accept the terms and 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.

Using the Terminal

Okay, so now that we have access to our Linux shell, what to do next? Let's go through these use cases:
  • Accessing my Windows files
  • Access internet resources
  • I install software

Accessing Windows Files

WSL mounts your Windows files on the /mnt/c mount point. To verify on yours type mount on the command prompt and look for C: on it. Your windows files should be there.
In case you don't know Linux, listing files is done with   ls  . This is the content of my C drive as as seen from WSL:

Accessing the Internet

Your WSL instance should have access to the internet. Testing the internet is as simple as doing a ping to Google:
You can also verify your network info with ifconfig:
 

Installing Software

Installing software on Ubuntu/Debian is done by the apt command. For example, this is how we search packages:
To install packages, use apt-get install. For example, to install Ruby on the Ubuntu WSL, run the command below:
sudo apt-get install ruby-full

Using git

We can leverage apt and install git with:
sudo apt-get install git
... # apt installs git
git --help # to get help
And, I'd recommend learn to use it on the terminal. Atlassian has an excellent tutorial to learn git.

Getting Help

Need help? The man tool is there to help you. For example, we could run the commands below to get help on git for example:
man git

Additional tip: try the new Windows Terminal

And, if you want to invest more time on your WSL, I'd suggest that you install the new Windows Terminal. Download the last release from GitHub and install it on your box. It's very customizeable and contains shells for WSL, PowerShell, Azure CLI and the traditional Windows terminal.

What's next?

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

Conclusion

Congratulations! You have the WSL installed on your machine and now you have a Linux terminal to starting playing with. Now what? The first thing I'd recommend is to get comfortable with basic system commands, understand the filesystem, learn to add/remove software and run administrative tasks on the terminal. WSL 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.

If you want to know more about my setup, here's why I use Fedora Linux with the fantastic i3 window manager on the desktop and CentOS on servers. Happy hacking!

References

See Also

    About the Author

    Bruno Hildenbrand      
    Principal Architect, HildenCo Solutions.