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
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Programming in C.
Lesson complete
Earn the 3 college credits for Programming in C
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: C Program Formatting Standards →← From Bell Labs to Modern Compilers: The History of CNext lesson: C Program Formatting Standards →
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.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Compare: C vs C++
Why take it here
Why students take Programming in C with UPI Study
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.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →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?
Why does the terminal say command not found after installing a compiler?
How do you compile and run a C program from the terminal?
How can you tell which compiler runs when you type gcc?
About the Programming in C course
How many college credits is Programming in C?
How much does Programming in C cost and what is included?
Which universities accept UPI Study credits?
How long does Programming in C take?
How are the exams done?
How do my credits reach my college?
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.
3 credits · NCCRSEnroll →