Write your first Code on Windows Subsystem for Linux.

Tola Ore-Aruwaji
3 min readJul 10, 2020

--

WSL

Windows Subsystem for Linux (WSL) is a way for you to run a Linux Environment including most Command-line tools, Utilities, and Applications directly on Windows. From a technical perspective, WSL enables you to run Unmodified L64 Linux binaries on Windows. It provides an Integrated experience with Windows.

For example, WSL makes it possible to run a Linux project from VS code or If you want to Open up a Bash Shell from File Explorer it’s also possible.

This article explains how you can write and run your first program on WSL.

PREREQUISITES:
Before you can Implement this tutorial you need to set up WSL on your system . Follow the process here to Install and Setup WSL.

In this article, I will illustrate how to setup C on the terminal and run programs on it.

Let’s get to it

  1. Run Sudo apt-get updateon your terminal, this will make sure that all the links to the repositories are up to date.

Sudo apt-get update; updates the package lists for upgrades for packages that need upgrading, as well as new packages that have just come to the repositories.

Sudo apt-get update on terminal

2. Install the GCC Compiler using sudo apt-get install gcc

Run Sudo apt-get install gcc on terminal.

3. Write a simple C program using by typingnano helloworld.c on your terminal. nano is a simple terminal-based text editor which means that you can start typing and editing the text immediately after opening the file.

helloworld.c is the filename. You can specify your own file name. 

4. Write a program in C Language. The program below Prints Hello world implemented on WSL!

Write your first program on terminal.

5. Save your code on the terminal.

After saving your file, you can compile your code using this commandgcc helloworld.c

6. You can access the Linux executable files contain programs written in a language like C and compiled so they can run in the Linux environment. The file generated can be accessed by typing file a.out on the terminal, It is a 64 bit Linux File.

Enter the file a.out Command on terminal.

7. The file generated can be implemented on the terminal by typing ./a.out this refers to a file called “a.out” that is in the current folder. If you type a.out it refers to the FIRST file of that name that is found in a list of folders where the list is held in a shell variable called “PATH”. Usually, the current directory, denoted by . is not included in the path. Hence, to execute anything that's not in the PATH, you need to specify the directory where it resides. Hence, the usage ./a.out

./a.out tells the terminal to execute the file named a.out in the directory (.) ie current directory

./a.outAfter typing this on terminal it prints the Sentence;Hello world implemented on WSL!
Enter the ./a.out command on terminal.

Congratulations you just wrote your first program on WSL! You can now Write and Compile more programs on your terminal.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇

--

--

Tola Ore-Aruwaji
Tola Ore-Aruwaji

Written by Tola Ore-Aruwaji

Software Craftsman. DevOps & Cloud Advocate.

No responses yet