Set Up C Compiler On Your Windows 10 Desktop Using WSL (For CS Students)
With the release of WSL (Windows Subsystem for Linux), we can install a Linux machine inside windows itself without going through the hassle of setting up a virtual machine or dual booting.
You can run the Ubuntu terminal inside windows just like you open an app.
Before we begin installing WSL make sure you are running on windows 10 version 1607 or above, to check your version press WINDOWS + R which opens the run dialogue, type in winver and press enter.
Mine is version 2004 so I will proceed with the installation if you don’t have the recommended minimum version go to settings and update to the latest version of Windows 10.
First step is to run windows Powershell as an administrator and run the following command and press enter
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
After the command has been completed do a system restart
After your PC is booted up open Windows PowerShell as administartor once again and run the following commands one after the other
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
After the commands has been completed do a system restart
Now we are ready to install Ubuntu, the easiest and intended way to install Ubuntu is to go to the microsoft store and search for and download Ubuntu.
Or If you are too lazy to download from the store, Click on the download button to download the installer from here.
After it is downloaded, Install and open it
Set Up a Username and password for your Ubuntu System (The password won’t show while you are typing)
Now we’ll install our compiler, for that run the following command and enter your password when prompted.
sudo apt install gcc
When prompted with this: “Do you want to continue? [Y/n]” type y and press enter
It’s Going to take a while. After it is done, your C compiler is ready,
Do your C program in the text editor of your choice, I recommend sublime text or Visual Studio Code. For this article I will use Notepad.
Save the file as yourname.c , the next step is to compile the program, for that open the folder that contains the C file and Hold down on shift key and right click on the mouse. You’ll see an option “Open Linux Shell Here” clicking on it will open up Ubuntu.
Now type in the following commands to compile your program, the syntax should be ” gcc yourname.c ” and to run the program ” ./a.out ” . In this case the command is
gcc abc.c ./a.out
There you go, your C compiler with WSL is set up and ready to go, please share this article with your friends who are looking for a good C compiler for windows 10.