This page aims to guide users on how to download Windows Subsystem for Linux (WSL) and Microsoft Visual Studio Code. This will help reduce the dependance of virtual machines such as VMWare Horizon as they rely on a stable internet connection as well as low traffic. Using WSL and Visual Studio on a personal computer lets you work whenever wherever as it is not dependant on an internet connection
The First step is to go and visit the official Microsoft Visual Studio wesbite and install the latest Visual Studio code. Since this is for Windows, the standard Windows version x64 was selected. Click on the link and let it download. Once it has downloaded, click on the .exe file to begin Installation.
This is what the start of the installation will look like. Accept all terms and conditions.
Select a place to install in your PC.
Make sure the bottom two checkboxes are selected.
Microsoft Visual Studio Code will begin to Install.
Once Installed Click Finish.
When VSC (Visual Studio Code) opens, this is what the home interface will be.
NOTE: the theme might differ.
Now Navigate to the Microsoft Store
In the search bar, type in UBUNTU and hit enter. You will see a list of different UBUNTU softwares to download
Choose the Latest one. In this case Ubuntu 22.04.2 LTS
Hit Get and let it install
Once Installed Click Open.
When you first open it, you may encounter this error, where it says that "The Windows Subsystem for Linux has not been enabled" This is normal. The following steps show how to resolve it.
Press the Windows key and search "Turn Windows Features on or off." Click on the first result and it should take you to this window.
In this window, check the following Boxes: "Virtual Machine Platform", "Windows HyperVisor Platform" and "Windows Subsystem for Linux". Please note this was done on a PC running an Intel Processor. This may look different for those running an AMD processor. Never the less, make sure that the virtual machine and windows subsystem for linux is checked. Once all selected, hit ok.
It will start to install.
Once Installed it will ask to restart. Make sure if any work is being done that it is saved. Then click "Restart Now".
Once Rebooted, go back into Ubuntu. This time the message should be different and it will say that it is installing. This will take several minutes so DO NOT close the window or shut off your PC
Once it is Installed it will ask you to create a UNIX Username. It is case sensitve as well so make it all lowercase
Like this. Now it will ask you for a password. Now it is very important that you make it something you remember or else resetting it is a pain. It is a hidden Password, i.e when you type it in, you cant see what you typed. So make sure to make it as simple and easy to remember as possible.
Like this. Now retype it.
Give it a few minutes and you will be greeted by a Success message and a screen similar to this. This means installation was successful and we can move forward.
Now to Install the C Compiler, known as gcc, run the following command:
sudo apt update && sudo apt install build-essential
For any command using the sudo keyword, it will ask you for your password. Type it in and hit enter
It will start installing and depending on your internet connection, it may take a while.
It will ask you if you want to continue, type in "y" and hit enter and it will install the files and dependencies. Again, this may take time as it depends on your internet connection.
As shown here.
Once done, it will stop and have the prompt to add a command.
type "clear" and press enter. This will clear the terminal. Then type "gcc --version and hit enter. It should show the version of gcc installed.
Now exit out of Ubuntu and open VSC.
To test this works, I created a file called test.c
Then, click on the extensions tab on the left handside and search for C/C++ Extension Pack This should also show as a prompt in the bottom left hand corner of the last step.
Install it.
Now we will set WSL as our default terminal. Go to:
View > Command Pallete (Ctrl + Shift + P)
In the Search box, type in:
Terminal: Select Default Profile
VSC should automatically recognise Ubuntu. Click on it
To check that Ubuntu is our default terminal click on:
Terminal > New Terminal
You should see the terminal open at the bottom which is now the Ubuntu terminal set as default
Now back in the extenstions tab, find the WSL extension and install it.
Once installed, create a file here named test.c and i wrote a simple program that outputs Hello World to the terminal. However we have errors.
To fix those erros, we need to download the compiler for it. Although installing Ubuntu with the sudo command installed gcc, vscode cant find the path. So, go to this website to download MSYS2. Click on the link to download the installer.
Once downloaded, run the installer.
Select your installation folder.
Just click next
Let it install.
Once installed, click finish.
When the terminal for MSYS2 opens, it will look like this
Type in the following command in the terminal window:
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
It will give you a selection. Just press enter.
Type in y and press enter
Once it is installed, you will know when it asks for more prompts
Go to the directory where you installed MSYS. For this machine it was in C drive > msys64
msys64 > mingw64
mingw64 > bin
Here is where the gcc executable lies.
Copy the directory
Once you have copied the directory, go back to the extensions page in VSC and click on its setting
Scroll down until you find C_CPP: Default Compiler and paste in your directory. After the \bin, add gcc.exe as shown in the screenshot. This will now set your default compiler
Next step is to add it into your PATH in your machine. Click on the Windows button, and type in edit environment variables. The window should look similar to the screeshot. Click on PATH and then the Edit button
Click new.
Add your copied directory but without the gcc.exe bit.
Now back to VScode, and you can see the error has gone. I created another program called main.c that just outputs Hello World and an addition of 2 numbers. To run it, in the terminal type in:
gcc -ansi -pedantic -Wall -Werror main.c -o main
Now note this will be different to you. you can name your file whatever with a .c extension and just replace main.c with that file name. This compilation will be covered more in the Unit COMP1000 - Unix and C Programming
Once Compiled, run the program by typing:
./main
And it should output whats shown on the screenshot.
This concludes the guide on how to install WSL and Visual Studio. Now note that this was primarily for C programmers, however this can be used for any coding language. I personally use WSL in Visual Studio to run Java and Python programs as well as C Programs. I prefer this method because it lets me work offline wherever as im not dependant on an internet connection like virtual machines such as VMWare Horizon.