Getting started with Windows Subsystem for Linux

The blog post from Scott Hanselman (1) and posts from Microsoft (2) (3), encouraged me to try a newly added feature in Windows 10 called Windows Subsystem for Linux (WSL). It allows you to run native linux programs directly on Windows. This post briefly describes the necessary steps required to get started with WSL.

First you need Windows 10 with Creators Update installed. Basic steps for installation can be found in Windows 10 Installation Guide (3).

To make all the steps work smoothly, I would recommend updating Windows from Settings/Updates and Security.

Make sure that Developer mode is selected in Settings/For developers tab.

To enable the “Windows Subsystem for Linux”, open PowerShell as Administrator and run:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Or the above step can also be performed by turning the check box for “Windows Subsystem for Linux” in “Turn Windows features on or off” dialog box. Restart the system for these changes to take place.

I installed Ubuntu directly from the Windows Store. This application is distributed from Canonical Group that allows to run Ubuntu terminal and run Ubuntu command line utilities including bash, ssh, git, apt and many more.

I had some difficulty while installing this application because the “Get” button was disabled, and I was not able to install the app. But after updating Windows 10 to the latest updates, this problem was fixed.

After Ubuntu has been installed, you can try various command line utilities. You can install Linux software using apt-get command. “Apt” stands for “Application Package Tool” that is used for downloading software packages from Ubuntu’s centralized software repositories and install them to your system.

To download an up-to-date package lists from the software repositories run:

$ sudo apt-get update

To install the package, run

$ sudo apt-get install packagename

More information regarding installing software in Windows 10’s Ubuntu Bash Shell can be found here (4) and (5).
In order to be able to compile C++ programs, we need a C++ compiler like gcc or clang. Run the following command that will install gcc along with other development tools that we need.

$ sudo apt-get install build-essential

Make sure that the gcc has been installed. Run the following command to check the gcc version.

$ gcc -v

Once we have a gcc toolchain properly installed, we can compile the C++ programs normally just as we do in Linux environment.

The other thing that interested me is to run a GUI application in WSL. As mentioned in the Microsoft blog (2) and the post from ICS (6), there is no official support for graphical applications for WSL. But, we can run some simple graphical applications by installing a separate X11 server and this worked for me while running gvim (graphical version of vim).

The detail steps on running a graphical Linux Desktop Applications from WSL can be found here (8). The first step is to install an XServer that can be downloaded from Xming website (9). The second step is to install the program. For example, run the following command to install GTK based vim editor.

$ sudo apt-get install vim-gtk

The third step is to set the display environment variable to point to the X server running on your Windows PC as follows:

$ export DISPLAY=:0

Finally, the fourth step is to launch the application as:

$ gvim

I’ve not tried to run other sophisticated GUI programs, but this one worked quite well for me. The next motivation would be try building Qt project as mentioned in the ICS blog post (6) and (10).

After trying out few commands in the terminal, it made me realize that it make sense to configure the console to look and feel like Ubuntu terminal. So, I found out this link (11) and (12) that helped me to look my Bash on Ubuntu on Windows 10 look like the Ubuntu Terminal.
WSL is a pretty deep topic and there is a dedicated blog site for this (7).

I think this is a great tool to experience Linux environment in a light weight process instead of using VM. But for running more complex GUI applications, it would be better to run them in VM.

References:

[1]: https://www.hanselman.com/blog/Building0verkillOnWindows10SubsystemForLinux2DASCIIArtDeathmatchGame.aspx
[2]: https://blogs.msdn.microsoft.com/wsl/2016/04/22/windows-subsystem-for-linux-overview/
[3]: https://docs.microsoft.com/en-us/windows/wsl/install-win10
[4]: https://www.howtogeek.com/261449/how-to-install-linux-software-in-windows-10s-ubuntu-bash-shell/
[5]: https://www.howtogeek.com/265900/everything-you-can-do-with-windows-10s-new-bash-shell/
[6]: https://www.ics.com/blog/run-ubuntu-linux-windows-one-weird-trick
[7]: https://blogs.msdn.microsoft.com/wsl/
[8]: https://www.howtogeek.com/261575/how-to-run-graphical-linux-desktop-applications-from-windows-10s-bash-shell/
[9]: https://sourceforge.net/projects/xming/
[10]: https://www.ics.com/blog/how-compile-qt-source-code-linux
[11]: https://medium.com/@jgarijogarde/make-bash-on-ubuntu-on-windows-10-look-like-the-ubuntu-terminal-f7566008c5c2
[12]: https://design.ubuntu.com/font/

Leave a comment