Setting Up the C Development Environment | Programming in C

UPI Study › Courses › Programming in C › Free lessons › Lesson 2.2 Free with a free account

Setting Up the C Development Environment

Programming in C · Chapter 2: C Language Setup, Data Types, Variables, and Console I/OSection 2.2 · lesson 9 of 787 min · free with a free account

← From Bell Labs to Modern Compilers: The History of CNext lesson: C Program Formatting Standards →

Earn 3 college credits for Programming in CRecommended for credit by NCCRS · Computer Science 240 · self-paced · one payment, lifetime access

In this lesson

Install a C compiler, fix PATH and run a first program.

  • Identify the compiler and editor needed to write C programs
  • Install GCC or Clang on Linux, macOS or Windows and verify it with --version
  • Explain how PATH is searched and fix a command not found error
  • Compile hello.c with the C17 standard and warnings, then run it

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (887 words). Read along, or search it.

Opening Analogy

A Kitchen for Your Code

A chef can't cook without a kitchen, and you can't turn C into a running program without a compiler. The good news: good C compilers are free, and setting one up takes about ten minutes. Then comes the best moment of a beginner's week: one command, and your own program comes alive.

What You Need

A Compiler and a Plain-Text Editor

You need two things. First, a compiler: the program that translates your C into machine code. The best known is GCC, the GNU Compiler Collection. It's free, and runs on almost every kind of computer. Second, a place to type. A text editor saves plain text. An IDE, an integrated development environment, adds extras. Color for your code, a Run button, and a list of errors. Visual Studio Code and Code Blocks are two free, popular ones. The compiler doesn't care what you typed in, as long as the file is plain text, with a name ending in dot c.

Installing

GCC on Linux, Mac and Windows

Installing depends on your computer. Either way, you type commands in a terminal: the text window where you give written commands. On Linux, the package manager installs GCC with the build essential package. On a Mac, x code select dash dash install brings Apple's command line tools. On Windows, MSYS2 installs a real GCC. Menus and version numbers change, so if a step looks different, check the installer's own page.

Version Check

When Typing gcc Starts Clang

First check after any install: ask the compiler to introduce itself, with dash dash version. On this Mac, typing gcc gives a surprise. The first line says Apple clang. On a Mac, the name gcc starts Clang, a different compiler. Clang and GCC take the same commands and the same options. Only the exact wording of their messages differs. So on screen we'll call Clang by its own name. Real GCC prints its own version line instead, starting with gcc. Your numbers may differ. That's fine, as long as you see a version and not an error.

PATH Explained

How the Shell Finds a Command

When you type a command name, how does the computer find that program? It doesn't search the whole disk. That would take ages. It checks a short list of folders, in order, and runs the first match. That list is called PATH. Think of a school office. The secretary doesn't search every classroom for you. She checks her short list of rooms. The which command shows where the search ended. Here, clang was found in the folder slash u s r slash bin.

Troubleshooting

Command Not Found Means a Missing Folder

Now watch what happens when the right folder is missing from the list. For this one command, PATH holds only one folder, slash t m p. The shell checks it, finds no clang, and gives up: command not found. The compiler is still installed. The list is missing a folder. Fix the list, not the compiler. Installers for Linux and the Mac add the folder for you. With MSYS2 on Windows, you usually add it yourself. Search the Start menu for environment variables, add the folder to PATH, then open a new terminal so it reads the new list.

Quick Check

Two Programs Named gcc

Quick check. Two folders on Sam's PATH both hold a program named gcc. The first folder's gcc is GNU GCC. The second folder's gcc is Apple clang. Sam types gcc dash dash version. What does the first line of the answer start with? Pause, and decide. It starts with gcc, the GNU GCC line. The search stops at the first match, so the first folder wins. Apple clang would answer only if its folder came first. And command not found needs no match at all, which isn't the case here.

First Program

Compiling and Running Hello

Time for the real thing. Open your editor, type this program exactly, and save it as hello dot c, in a folder you'll remember. What every line means comes later, in lesson 3.6. For now, open a terminal in that same folder. This is the full command. Dash s t d equals c 17 asks for the C17 standard. Dash Wall and dash W extra ask it to report problems. And dash o hello names the finished program hello. Press Enter, and nothing is printed. That's success. Compilers stay quiet when everything is fine. Now run it with dot slash hello. The line after it is your program talking. On Windows, the file is named hello dot e x e, and dot slash hello still runs it.

Edit, Compile, Run

Greeting a New Name

One more test. Change the text inside the quotes to your own name. Here, Priya. The program you run is the compiled file, not the text. So compile again, then run. Now it greets Priya. Edit, compile, run: that's the loop you'll repeat in every lesson.

Story Ending

Test the Setup First

On her new laptop, Priya typed gcc and got command not found. She had installed the compiler, but its folder wasn't on PATH. Sam didn't touch the compiler. He added one folder to PATH, opened a new terminal, and the version check answered. Test the setup before you write any code, Sam says. Then a bug is a bug in the code, not in the kitchen.

Key Takeaways

Compiler, Editor, PATH and Run

To recap. You need a compiler, such as GCC or Clang, and an editor that saves plain text ending in dot c. PATH is the ordered list of folders searched for a command. Command not found usually means a missing folder. Check with dash dash version, then compile with the full command and run with dot slash.

About Programming in C at UPI Study

Programming in C (Computer Science 240) is a self-paced online course of 78 video lessons in 11 chapters, from pseudocode and your first program to data types, decisions, loops, functions, arrays, strings, pointers, files, structures, dynamic memory and linked lists. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: C vs C++

Why take it here

Why students take Programming in C with UPI Study

How programs work close to the machineProgramming in C teaches how a program uses memory: variables and data types, control flow, functions, arrays and strings, pointers, files, structures and dynamic memory. C is the base for operating systems, embedded devices and many computer-science courses.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Programming in C carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Setting Up the C Development Environment

What is the difference between GCC and Clang?
GCC and Clang are two separate, free C compilers that accept the same common commands and options, such as -std=c17, -Wall and -o. GCC is the GNU Compiler Collection, available for almost every kind of computer. On a Mac, typing gcc actually starts Apple clang. For a beginner, the main visible difference is the wording of their error and warning messages.
Why does the terminal say command not found after installing a compiler?
Command not found usually means the compiler's folder is missing from PATH, not that the install failed. PATH is an ordered list of folders the shell searches when a command name is typed, and it runs the first match. Linux and Mac installers usually add the folder automatically. With MSYS2 on Windows, add the folder to PATH yourself, then open a new terminal so it reads the new list.
How do you compile and run a C program from the terminal?
Compile with a command such as gcc -std=c17 -Wall -Wextra hello.c -o hello, then run the result with ./hello. The -std=c17 option picks the standard, -Wall and -Wextra turn on warnings, and -o names the output program. A compile that prints nothing has succeeded. On Windows the file is named hello.exe, and ./hello still runs it. After every edit, compile again before running.
How can you tell which compiler runs when you type gcc?
Run gcc --version and read the first line: GNU GCC starts with gcc, while Apple's compiler starts with Apple clang. The which command shows the folder the program was found in. When two folders on PATH both hold a program named gcc, the shell runs the one in the earlier folder, because the search stops at the first match.

About the Programming in C course

How many college credits is Programming in C?
Programming in C (Computer Science 240) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Programming in C cost and what is included?
$250, paid once, with lifetime access: all 78 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Programming in C take?
It is self-paced with no deadlines. The 78 lessons total about 9 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Programming in C.

78 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Programming in C
3 credits · NCCRS
Enroll →