Install Virualization Software and Ubuntu 22.04

In this course we are going to be working with the Linux operating system. You will do this by installing virtualization software on your computer and then running Ubuntu 22.04 in a virtual machine.

The instructions to get everything set up will differ depending on which platform you are running.

If you are using a Mac with an Apple Silicon processor, you should follow these instructions to install UTM and Ubuntu.

If you are using a Mac with an Intel processor, you should follow these instructions to install VirtualBox and Ubuntu.

If you are using Windows, you should follow these instructions.

Basic terminal commands

If this course is your first exposure to working in a terminal on Linux, you may want to read through a basic tutorial on the Linux command line interface.

Here is a link to a tutorial for Ubuntu that covers the basic things you need to know to use the command line effectively.

Setting up additional software in the virtual machine

Before we can start writing C code in the virtual machine we will need to install some development tools. Open a Terminal window in Ubuntu and execute the commands

sudo apt update
sudo apt upgrade
sudo apt install build-essential gdb

to set up the package manager apt and install a couple of packages. The build-essential package contains the gcc compiler tools and other assorted tools you will need to develop C programs. The gdb package is the GNU debugger you will use to debug the programs you write.

Installing Visual Studio Code

Our primary development environment for this course will be Visual Studio Code. We will be running VS Code in the virtual Ubuntu machine that you just set up.

Start by opening the Firefox browser on Ubuntu, then use that browser to go to the download page for Visual Studio Code. On that page you will see links to download VS Code for various operating systems. If you are using a Mac with Apple Silicon you will need to download the Arm64 .deb installer. For Intel Macs and Windows computers you should download the x64 .deb installer.

Once you have downloaded the installer, go back to the terminal and run these commands:

cd Downloads
sudo dpkg -i *.deb

This will install VS Code in your Ubuntu virtual machine.

Once VS Code is installed you can launch it from the Ubuntu launcher. To access the launcher, click on the grid icon in the lower left hand corner of the Ubuntu desktop. Visual Studio Code should then show up as one of the icons in the launcher. You can click on the application icon to launch it, or you can right-click on the icon and select the 'Add to Favorites' option: this will add the VS Code icon to the dock on the left side of the window.

Visual Studio Code is a development environment that you can use to develop software in a wide variety of different languages. The Code application is a shell program that makes use of extensions to provide support for different development tools.

There are a series of tabs running down the left hand side of the main application window. Click the extensions tab at the bottom to bring up the extensions view. Here you will see a long list of available extensions. Since we are going to be doing C development, you will want to install the C/C++ Extension Pack.

First project

Next, we are going to set up our first example development project.

First, we are going to set up a project folder for our first project. To create this project folder, type the commands

cd ~
mkdir hello

This will create a project folder for your first project. Next, click the first tab in the tab bar on the left of the VS Code window. This will open the explorer view. Click the Open Folder button in the explorer view and then select your new hello folder in the dialog that pops up.

Since the project folder is empty, we will need to start by creating a C source code file for our example program. Click the New File button, or select New File from the File menu to create a file named hello.c.

Paste the following code into the editor

#include <stdio.h>

int main() {
    printf("Hello, Linux!\n");
    return 0;
}

and save your changes.

To compile the example program, select Run Build Task... from the Terminal menu. Select the gcc build active file option. You should then see a message in the Terminal pane confirming that program built successfully.

To run the program, select the command Run Without Debugging in the Run menu. When the program runs you should see the "Hello, Linux!" message in the terminal pane.

You can also run the program directly from the terminal pane by typing the command

./hello