Setting Up
Fifteen minutes, once. You will install a C compiler, get the lesson files and run your first program from a terminal. The same guide is on the site at https://cfromthegroundup.com/setup.
What You Need
- A C compiler. Clang and GCC both work; on every system below the command
is called
cc. - A terminal, the text window where you type commands. Every lesson is compiled and run from one.
- A text editor for reading and changing the code. Any editor works; VS Code is a good free choice.
Most lessons are portable C and run anywhere. Lessons 26, 29 and 30 use POSIX system calls and lessons 33 and 35 use the ncurses library, so those need macOS, Linux, or Linux inside Windows (WSL). The instructions below set all of that up.
macOS
Open Terminal (in Applications, Utilities) and install Apple’s command line
tools. They include the Clang compiler, make and ncurses:
xcode-select --install
A window asks you to confirm the download. When it finishes, check that the compiler answers:
cc --version
On macOS, gcc is another name for Clang. That is fine: every lesson compiles
with either.
Linux
Install the compiler, make, the ncurses headers and git (to get the lesson
files) with your package manager.
Debian, Ubuntu and Linux Mint:
sudo apt update
sudo apt install build-essential libncurses-dev git
Fedora:
sudo dnf install gcc make ncurses-devel git
Arch Linux:
sudo pacman -S base-devel ncurses git
Then check that the compiler answers:
cc --version
Windows (WSL)
On Windows, take the course inside the Windows Subsystem for Linux: a real Ubuntu that runs next to Windows. This is the supported way to take the course on Windows, and every lesson works there, including the POSIX and ncurses ones. Open PowerShell as administrator and run:
wsl --install
Restart when asked, then open Ubuntu from the Start menu and choose a user name and password. From then on you are on Linux: follow the Debian and Ubuntu steps above.
Your Windows drives appear inside Ubuntu under /mnt/ (for example
/mnt/c/Users/you), but keep the lessons in your Ubuntu home folder, where
compiling is faster. VS Code with its WSL extension can edit files there
directly.
Using the Terminal
A few commands are all you need:
pwdprints the folder you are in.lslists the files in it.cd foldermoves into a folder, andcd ..moves back up one.
Folder names with spaces must be quoted: cd "Part 1 - The Beginner Path_ Core Concepts".
Press the Tab key to complete a name for you.
Get the Lesson Files
Every lesson on the site has a Download button on each source file. To get the whole course at once, clone the repository with git:
git clone https://github.com/dunamismax/c-from-the-ground-up.git
cd c-from-the-ground-up
The folder names contain spaces, so put quotes around them when you change into one:
cd "Part 1 - The Beginner Path_ Core Concepts"
Your First Program
In the folder that holds 1_hello_world.c, compile it, then run the program
the compiler made:
cc -Wall -Wextra -std=c17 -o 1_hello_world 1_hello_world.c
./1_hello_world
If the terminal prints Hello, World!, you are ready. Head to
Lesson 1: Hello, World! to learn what each line of
that program does.
What the Flags Mean
ccruns the C compiler.-Wall -Wextraturn on warnings. A warning is the compiler pointing at code that is legal but probably wrong. Read every one; the course’s own code compiles with none.-std=c17picks the version of the C language standard to follow. This course teaches C17, which every current compiler supports.-o namenames the program the compiler writes. Without it, you geta.out../nameruns a program from the current folder. The./is needed because the shell does not look for programs there by default.
Troubleshooting
cc: command not found: the compiler is not installed yet. Repeat the steps for your system above.No such file or directory: you are not in the folder that holds the lesson file. Runlsto see what is there, andcdinto the right folder.undefined reference to `pthread_create`(or tosqrt): the lesson needs a library. Use the exact command in its “How to Compile and Run” section; it includes-pthread,-lmor-lncurseswhere needed.cannot find -lncursesorncurses.h: No such file: install the ncurses development package (libncurses-devorncurses-devel). Some systems call the libraryncursesw: try-lncursesw.- The program waits and nothing happens: it is probably waiting for you to type something. Press Ctrl+C to stop any program.