Appendix A
Linux
A.1 Options for Installing Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
A.2 Getting Ubuntu Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
A.3 Downloading and Installing VirtualBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
A.4 Install and Update Linux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
A.5 Install Programming Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
All examples in this book are tested in the Linux programming environment. Linux is a
widely used operating system. It is free in two senses. First there is no need to pay anyone
to get the operating system and many tools for Linux. Second, all the source code for Linux
and many associated tools is freely available. Furthermore, this code can be modified and
used by anyone, for personal or business reasons. Google’s Search Engine uses Linux. So
does the software on the International Space Station. The mobile operating system Android
is based on Linux. Some estimate that over 60% of web servers run UNIX-based operating
systems, and among them Linux dominates.
Sometimes people are surprised by how widely Linux is used. Consider Amazon EC2
(elastic cloud computing). It gives the options for Linux and Windows. For the same ca-
pabilities (measured by the number of virtual processors and the amount of memory), the
price for a Linux instance is about half of the price for Windows. Many software companies,
such as Oracle and SAP, sell programs running on Linux. Why? Because many customers
prefer to use Linux for a variety of reasons. If a company does not support Linux, then this
company forgoes a large market segment. Linux is widely used in universities and compa-
nies. The skills learned using Linux are widely applicable. Learning Linux is important for
developing an understanding of computing in general, and is especially important in some
business and scientific fields.
A.1 Options for Installing Linux
There are several options for setting up a Linux programming environment:
Buy a computer that already has Linux installed. Many computer vendors have this
option. This is the easiest solution.
Build your own desktop computer: You can buy a motherboard, a processor, a hard
disk, a display, ... After assembling the hardware, then install Linux. This is great
experience for understanding the components of a computer. You will know precisely
what is inside your computer.
Install Linux side-by-side with an existing operating system (also called dual boot).
This is possible if your computer already has another operating system (such as Mi-
crosoft Windows or MacOS). MacOS and Linux are both “UNIX-based” but some of
the fundamentals are different. As of writing this book, some programming tools are
443
444 Intermediate C Programming
more stable in Linux than in MacOS. Therefore, I recommend installing Linux even
if you already have MacOS. The advantage of dual booting is that each operating
system has the resources of the entire computer. The disadvantage is that it is more
difficult for the operating systems to share data and co-operate, since only one operat-
ing system can be used at a time. Changing the operating system requires restarting
the computer.
Dual booting used to be more popular than it is today. Now we have access to high
quality and affordable (or free) virtual machines that are well supported by special
hardware. This is my preferred option because of the convenience, and also the wide-
spread usage in industry. A virtual machine is a computer program that runs an
operating system inside of it. The operating system thinks it is running directly on
the hardware, but it is actually embedded in a type of container. The vast majority
of modern computers have special hardware to support virtual machines. The two
operating systems run simultaneously, and it is often easy to move data between the
two “computers”—either moving files, or simply using the clipboard to copy data
from a Windows or MacOS program and paste it into a running Linux program. The
two operating systems must share the resources of your computer. If your computer
has less than 4GB of memory, you may notice occasional slowdown and you should
consider dual booting.
Assuming that your computer has 4GB or more memory, and is currently running
Windows, then when we install a virtual machine, Windows is called the host operating
system. The operating system (Linux) inside the virtual machine is called the guest
operating system. There are several choices for a virtual machine. VirtualBox from
Oracle is an excellent choice and it is free.
If you choose dual boot or virtual machine, you should always save the files already in
your computer before installing Linux. It is possible (even though unlikely) that something
may be wrong and you may lose the files in your computer.
After choosing how to install Linux, you now have to choose which distribution of Linux
you want to use. The common choices are: Fedora, Ubuntu, Mint, and SUSE. This chapter
uses Ubuntu as an example, but all of the distributions listed above are good choices. The
following sections explain how to install Linux as dual boot and how to install Linux inside
Virtualbox.
A.2 Getting Ubuntu Linux
To install Linux, first download the most recent image. An image contains all the files
needed for installation. The file should have an .iso extension. Please go to web site
www.ubuntu.com. Select the correct iso file and click “Download”. The size of a CD iso file
is approximately 700 MB. It is helpful to find a fast network connection before downloading
the file. Please select the correct version for your computer. If your computer is bought
after 2009, then it is likely to use a 64-bit CPU and thus you should download the 64-bit
installation ISO file.
If you want to make the computer dual boot, then you need to find a flash drive that
is at least 700 MB. The iso file cannot be copied onto the flash drive. Instead a special
program is needed to rewrite all of the data on the flash drive such that it looks like what
the iso file specifies. This will make the flash drive bootable. If you search on-line “ISO
to USB”, then you can easily find a program to do this. After you make the flash drive
Linux 445
bootable, keep the flash drive plugged into the computer and restart the computer. When
the computer restarts, and for a few seconds, press F2 (or F10 or F12, depending on the
computer’s firmware or BIOS, namely basic input/output system) to change the computer’s
settings. You will need to select the flash drive as the first choice for booting the computer.
Save the change and restart the computer. Skip the next section and go directly to Section
A.4.
A.3 Downloading and Installing VirtualBox
The following pages explain how to install VirtualBox. Please go to the web site www.
virtualbox.org. Click “Downloads” and choose the correct program for your computer.
For example, if your computer runs Windows, then you should select “Windows hosts”.
After downloading the VirtualBox program, run the program. In most cases, you can use
the default settings by clicking “Next” or “Yes”. Your computer will disconnect from the
network for a short moment during installation. This is expected.
A.4 Install and Update Linux
If you use VirtualBox, you need to start the virtual machine. It will ask for the location
of the iso file downloaded earlier. The virtual machine boots with a starting page. If you
do not see this page, try to download a 32-bit iso file and use it in the previous step.
Click “Install Ubuntu”. If you use dual boot, you will see the same starting page, without
the VirtualBox window. Follow the instructions to install Linux. In VirtualBox, install
the “Guest Additions”. The Guest Additions allows Linux to use the full screen of your
computer. It also allows for seamless use of the mouse between the guest and host operating
systems. Ubuntu will inform you if any of the installed programs needs an update. In some
cases, after installing the updates and restarting the virtual computer, you will need to
install the Guest Addition again.
A.5 Install Programming Tools
This book introduces some programming tools. Please install the following tools: emacs,
valgrind, ddd, and git. Click the “Software Center” at the toolbar on the left side. Search
“emacs” and install it. I use emacs because it can automatically indent C programs and
makes the programs easier to read. This is another example when using the right tools is
important. Correct indentation helps prevent careless mistakes, such as forgetting to add
the closing braces }. To indent your program in emacs, follow this procedure: Select “Edit”
at the menubar click “Select All” press the Tab key save the file. These steps are
all you need to do for indenting your programs.
Now you have a computer running Linux, and have also installed some programming
tools. This chapter gives a quick overview about how to install and update Linux, as well
446 Intermediate C Programming
as to install new programs. There is a lot of information available on-line. Be aware that
instructions change over time, and the Internet keeps a lot of old and outdated information
around. It is important to find up-to-date instructions when managing Linux. Linux is widely
used in business and science for good reasons: Linux is powerful and flexible. Spend some
time to become familiar with Linux and the knowledge can help you understand computers
more deeply.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset