Section 0f

Installing the C tools - VirtualBox


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Installing VirtualBox

VirtualBox is a virtual machine where you can run another operating system differing from the host systems (the OS your computer runs on) OS. It is helpful if you want to use Linux but do not want to buy another computer. VirtualBox can create virtual environments for almost any OS. To start go to the VirtualBox webpage by clicking here !

VirtualBox Page

 

Once at the webpage click the download link and it will take you to this page.

Platform Packages

 

If you are on Windows select the "Windows hosts" option and for Mac select "OS X hosts".

Download Start

 

Then it will start downloading an executable open it and the VirtuaBox installation process will automatically begin.

Executable

 

Open the file and begin the process by following the onscreen instructions.

Wizard Setup

 

When clicking next keep all of the default options that are provided. This is the easiest way to set up VirtualBox.

VirtualBox Setup

 

There will be a warning in which VirtualBox states that it will temporarily disconnect your computer from the internet. This shouldn't take too long so click yes and continue.

Warning

 

Then on the final set up page click install and the installation should begin immediately.

Install Page

 

This should be it for installing VirtualBox. Once it's finished you should see something similar to this:

VB GUI

 

Downloading and Configuring Ubuntu in VirtualBox

But you're not finished yet. The virtual machine that you'll be working on still needs to be configured. This page will show how to install Ubuntu, a popular Linux distribution. First go here and we will download Ubuntu.

Navigate to the Download tab and click on the Ubuntu Desktop download page.

Ubuntu Page

 

Download the one that says Ubuntu 20.04.2.0 LTS. LTS stands for long term support. Once you hit download you want to save the .iso file to your machine.

Download Page

Save .iso File

 

Once it is saved go back to VirtualBox and click the new Icon.

Create New

 

It will then ask for a name; you can call it anything but for simplicity call it Ubuntu. Select Linux as the type and then select the version it should be in there by default if not go in and change it to what is needed. If you are running on a 32-bit system be aware that you'll need to use the Ubuntu(32-bit) option under version.

Name & OS

 

Click next; you are going to need to tell VirtualBox how much memory it can have access to. There is a recommended amount but you can slide it anywhere within the green section.

Memory Space

 

Then select create a virtual hard disk now and then choose VDI for the hard disk file type.

Virtual Hard Disk

Hard Disk File Type

 

You want to choose dynamically allocated and then continue.

Allocation Type

 

Then you will be asked to choose the file location and the default size is highly reccomended.

Then click create and it will create a Virtual Machine with Ubuntu.

Start!

 

Setting up Ubuntu

 

Now that you have the Ubuntu virtual machine in VirtualBox we will need to set it up as well. Select the one you just created and hit start.

 

When you hit run for the first time make sure you select an appropriate drive that contains your .iso file. Sometimes the program will select a default but if the .iso file is not in that drive it will not work properly. So make sure to choose the appropriate drive.

Start Setup Disk

 

Then follow the instructions on-screen to set up Ubuntu. Most are self explanatory but there will be pictures here to help you through the process.

Step 1

 

Step 2

 

Step 3

 

Step 4

 

Step 5

 

It will ask you also if you want to send information it is a good idea to just select no. It will also ask for location access and for a password. It is suggested that you make it so that you do not have to type in your password every time you log in, you will want to select the Log in automatically option. Once that is finished you will need to restart the virtual machine; it should do it on it's own but if not click the battery icon in the top right and then power options and restart or you can just power the virtual machine off.

Restart

 

Command GCC

 

Once you restart it, come back in and install the C compiler. Open the terminal and type in the following command:

Command GCC

Since we are using the "sudo" command the system will request the password. Then when prompted in the terminal select Y and click enter and it'll download the C compiler.

 

Now that the C compiler is downloaded onto the virtual machine you can create your very first program! In your terminal you are going to need to open up a text editor. Some popular ones are atom, vim, or gedit. This page will demonstrate how to create a C program using atom.

To install atom open the terminal and input the command below the terminal will prompt you for your password again. A quick tip: Once you input the password, the terminal will not prompt you again within the same terminal session.

Install Atom

 

Now that atom is installed on the virtual machine. The software can be opened directly from your terminal by simpily typing atom and then enter.

 

Once you have atom open navigate the file drop down in the upper left of the window then select new file from the menu.

Atom New File

 

Time to code! Once you have a new file open the place to start is by essentially getting what you need from the library. For this main function we will need to be able to print so we need to grab the standard input/output and this is represented at the very top of the file.

#Include

Now that you have the pound include we can move on to the main function. In C the main function is represented as an int because if the function executes all the way through it returns a 0. A blank C file with only a main function looks like this.

Blank Program

Now that the file has the bare bones of a C program we can actually add some flavor to the program with a print statement. A print statement is demonstrated below.

Print Statement

Great! You have written your very first C program! Next you need to save and compile it. Save it somewhere you can find it. Open up the terminal. Once in the terminal you will have to navigate to wherever you saved the file.

 

Using a command called cd we can navigate within the file system. This command means change directory. To see what is in the current directory use the command ls. This command is called the list command and will display all files and folders that are in the current directory. Note that when a new terminal window is opened the current directory is always the home directory.

Terminal

 

Commands

 

Now that you have navigated to the C file we need to compile it before we can run it using the C compiler that was downloaded earlier.Use the below command to compile the file. The -o in the command just names the executeable file something other than the default. The -Wall flag that comes before the file name enables all of the compiler's warning messages.

 

Basic Compile Command

 

Now that the file is compiled we should check to see if the executeable file in the directory you can use the ls command. The arrow in the below picture points to the executeable that you have just created.

 

Executeable?

 

And now, we can run the program! Just type in ./test , so a dot and a slash and then the name of the executeable. Note that if you did not use the -o flag the name of the executeable by default will be a.out

 

Running

 

Now you know the basics!