Video Coming Soon...

Created by Zed A. Shaw Updated 2024-07-27 03:36:01

Exercise 0: The Setup

The traditional first exercise, exercises 0, is where you setup your computer for the rest of this book. In this exercise you'll install packages and software depending on the type of computer you have.

If you have problems following this exercise then simply watch the exercise 0 video for your computer and follow along with my setup instructions. That video should demonstrate how to do each step and help you solve any problems that might come up.

Linux

Linux is most likely the easiest system to configure for C development. For Debian systems you run this command from the command line:

$ sudo apt-get install build-essential

Here's how you would install the same setup on an RPM based Linux like Fedora, RedHat, or CentOS 7:

$ sudo yum groupinstall development-tools

If you have a different variant of Linux simply search for "c development tools" and your brand of Linux to find out what's required. Once you have that installed you should be able to type:

$ cc --version

To see what compiler was installed. You will most likely have the GNU C Compiler (GCC) installed but don't worry if it's a different one than what I use in the book. You could also try installing the Clang C compiler using the Clang's Getting Started Instructions for your version of Linux, or searching online if those don't work.

Mac OSX

2024 Note: Now you only install XCode from the Apple store and there are no more DVDs. If you don't have internet access I think you can go to an Apple store and ask to use the network to download XCode. They'll probably let you or help you.

On Mac OSX the install is even easier. First, you'll need to either download the latest XCode from Apple, or find your install DVD and install it from there. The download will be massive and could take forever, so I recommend installing from the DVD. Also, search online for "installing xcode" for instructions on how to do it. You can also use iTunes to install it same as you would a generic app, and if you do it that way you'll receive updates automatically.

To confirm that your C compiler is working type:

$ cc --version

You should see that you are using a version of the Clang C Compiler, but if your XCode is older you may have GCC installed. Either is fine.

Windows (2024 Installer)

On July 2024 I released a set of Windows Installers that automate much of the installation for many different programming languages. Included in that list is a full setup for modern C/C++ development, in addition to installers for Python, Ruby, Crystal, Zig, Rust, and many more. These installers are nothing more than simple little PowerShell scripts that install everything needed to work as a programmer, including text editors, shells, compilers, and other tools.

To use the script you run these two commands in PowerShell to get the base setup:

irm https://learncodethehardway.com/setup/base.ps1 -outfile base.ps1
powershell -executionpolicy bypass .\base.ps1

Feel free to edit the base.ps1 script to remove any packages you don't want, but most of these are simple tools you'll probably need. Once everything is installed then you'll want to close this PowerShell window and open a new PowerShell window to reset the PATH.

In the new PowerShell window you then run this command to install winlibs and other build tools like Meson and CMake:

irm https://learncodethehardway.com/setup/cpp.ps1 -outfile cpp.ps1
powershell -executionpolicy bypass .\cpp.ps1

Once this is done you can now start using Windows Terminal, the latest GNU C/C++ compilers, Meson, CMake, and many other tools. There is also an optional installer that adds useful tools such as ugrep which you may want:

irm https://learncodethehardway.com/setup/extras.ps1 -outfile extras.ps1
powershell -executionpolicy bypass .\extras.ps1

As usual, close your Terminal tab and open it again to get the PATH updates. You should also open these files in a text editor and review them. The list of packages installed is at the bottom.

Text Editor

2024 Update I've updated my recommendation here to use Geany, if you have opinions on VisualStudio Code for C editing then let me know in a bug report.

The choice of text editor for a programmer is a tough one. For beginners I tell them to just use Geany since it's simple and works for code. However, it doesn't work in certain internationalized situations, and chances are you already have a favorite text editor if you've been programming for a while.

With this in mind, I want you to try out a few of the standard programmer text editors for your platform and then stick with the one that you like best. If you've been using Geany and like it then stick with it. If you want to try something different, then try it out real quick and pick one.

The most important thing is do not get stuck picking the perfect editor. Text editors all just kind of suck in odd ways. Just pick one, stick with it, and if you find something else you like try it out. Don't spend days on end configuring it and making it perfect.

Some text editors to try out are:

There is probably a different editor for every person out there, but these are just a few of the free ones that I know work. Try a few out, and maybe some commercial ones until you find one that you like.

WARNING: Do Not Use An IDE

You should avoid using an Integrated Development Environment (IDE) while you are learning a language. They are helpful when need to get things done, but their help tends to also prevent you from really learning the language. In my experience, the stronger programmers don't use an IDE and also have no problem producing code at the same speed as IDE users. I also find that the code produced with an IDE is lower quality. I have no idea why, but I highly recommend if you want deep solid skills in a programming language that you avoid IDEs while you're learning.

Knowing how to use a professional programmer's text editor is also a useful skill in your professional life. When you're dependent on an IDE you have to wait for a company to sell you an IDE before you learn newer programming languages. This adds a cost to your career, and prevents you from getting ahead of shifts in language popularity. With a generic text editor you can code in any language, any time you like, without waiting for anyone to add it to an IDE. A generic text editor means freedom to explore on your own and manage your career as you see fit.

Previous Lesson Next Lesson

Register for Learn C the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.