Using WSL2 as your main development environment for Linux based university courses.

Many of us tried using the sluggish, full of problems VM’s given by the University course staff.
Many of us had a lot of trouble using those machines and developing on them, but NO MORE!
Let me introduce you: WSL2 — Your savior!

Matan Cohen
4 min readJan 31, 2021

Important: If your course staff specifically mentioned that you HAVE TO use a 32bit system — You can use this article if and only if your own system is 32bit and by making sure that the Subsystem is 32bit after the installation.
This can be done by using lscpu in the command line and checking the “Architecture” and “CPU op-mode(s)” sections.

What is WSL2?

“WSL 2 is a new version of the Windows Subsystem for Linux architecture that powers the Windows Subsystem for Linux to run ELF64 Linux binaries on Windows. Its primary goals are to increase file system performance, as well as adding full system call compatibility.” — Microsoft docs

In other words — WSL2 is a Linux Subsystem built into our own Windows PC. This Subsystem can help us with daily tasks such as writing code with Linux terminal, developing C programs and compiling them with GCC, and many many more!
Students — This Subsystem and I are here to help YOU to succeed in the upcoming semester without breaking a sweat!

With WSL2 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 your own GNU/Linux distribution package manager.
  • Invoke Windows applications using a Unix-like command-line shell.
  • Invoke GNU/Linux applications on Windows.

Then, Here we go!

Installing WSL2

First, make sure that your windows version is up to date:

Use WinKey + R and type “winver”, click “OK” and check if your Windows version and build version follow these requirements:

  • For x64 systems: Version 1903 or higher, with Build 18362 or higher.
  • For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.

1. enable Windows Subsystem for Linux: open your PowerShell with Administrator privileges, and run:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

2. in the same PowerShell window, enable virtualization with:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

And make sure that virtualization is enabled in your BIOS (check your motherboard manual for this step).

Now let’s make sure that WSL feature is enabled by pressing “Start” and searching for “features”, then click Turn Windows Features on and off and scroll all the way down until you see “Windows Subsystem for Linux”, make sure it is enabled, if not, manually enable it.

3. After restarting your PC, you should have the WSL installed.
Download the Linux kernel update package and install — then restart again.

4. Set WSL2 as your default WSL version:

wsl --set-default-version 2

5. Download Ubuntu 16.04 appx and install.

First steps with WSL2 and Ubuntu 16.04

After installing the WSL2 and Ubuntu 16.04, lunch it through Start menu — Just search for “Ubuntu 16.04 LTS” and run the app.

First, you have to set your administrative user credentials like username and password, please remember those credentials.

Ubuntu first boot on WSL2

Now, make sure your packages are up to date with:

sudo apt update

Install the right GCC version with make with these two simple commands.
note: GCC version may differ between each course and university, the version below is compatible with “The Open University of Israel” courses.

sudo apt-get install make
sudo apt-get install gcc-5 5.4.0

Then, you can start using your Ubuntu System.

Using Visual Studio Code with WSL to write and debug C code

In order to use your brand new WSL system for Uni purposes, make sure that you have Visual Studio Code installed on your computer — then open your Ubuntu app and run: code

This one will update the code server and open a new Visual Studio Code window that inherits the WSL environment.

Code server update

You can now install C extensions and run + debug C code (I’ll not cover this section here because there are plenty of guides out there, just google it 😉)

Extensions that I use in order to compile, run and refactor code in C:

C/C++
Code Runner

A great tutorial for VSCode configuration for C/C++

--

--