Hey everyone, I’m Jake from [my terminal supply company – no name drop, just keep it natural], and if you’ve ever stared at a blank terminal window wondering how to turn that random code you scribbled into actual working software, this post’s for you. For months, I’ve been sending our rugged, workhorse terminals to devs, students, and even indie game makers, and one question comes up more than any other: “How do I actually use gcc in a terminal?” Today, I’m breaking this down like I would to a new intern who’s never touched a command line, no stuffy jargon, no confusing fluff, just real stuff that works, and a little nod to why our terminals make this whole process way less annoying. Terminal

First, let’s get one thing straight: gcc isn’t some magic black box. It’s just a compiler – a tool that takes code you write in C, C++, or a handful of other languages, turns it into something your computer can run, like an app or a game. And since every single one of our terminals is built to handle long, steady coding sessions (no lag, no random crashes mid-compile, even if you’re running 10 other tools at once), you’ll never have that frustrating moment where your session locks up right as your code’s about to work. But enough about our gear for now – let’s dive into the actual steps.
First things first: Is gcc even installed on your terminal? This is the most basic, and most missed step. A lot of new devs fire up a terminal, type gcc, and get a “command not found” error, and that’s because some OSes don’t include gcc by default. Let’s fix that first. If you’re on Ubuntu, Debian, or any Debian-based Linux, just fire off this command: sudo apt update && sudo apt install build-essential. That’s it – build-essential grabs gcc and all the other little tools you’ll need to compile code without extra headaches. If you’re on Fedora or RHEL? Swap that out for sudo dnf group install "Development Tools". For macOS? You’ll need Xcode Command Line Tools – just type xcode-select –install, and it’ll prompt you to download the tiny (but necessary) package for gcc. And yeah, all our terminals work flawlessly with all these setups, no weird driver hoops to jump through.
Once gcc is installed, let’s test it real quick to make sure it’s working. Open your terminal (the same one from our gear, or any, but why not use the one that’s built to handle this stuff?). Type gcc –version and hit enter. If you get a line that says something like gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, you’re golden. If not? Double-check your install command, and make sure you typed it right – typos happen to everyone, even me.
Now, let’s get to the fun part: actually compiling code. Let’s say you wrote a super simple C program, like a “Hello World” script. Open your favorite text editor (nano, vim, VS Code – all work perfectly on our terminals), type this code:
#include <stdio.h>
int main() {
printf("Hello from gcc on my terminal!\n");
return 0;
}
Save that file as hello.c. Pro tip: name it something descriptive, not code123.c – you’ll thank yourself later when you have 20 files. Now, go back to your terminal, and make sure you’re in the same folder where you saved hello.c. If you’re lost, type ls to list all the files in your current directory – you should see hello.c pop up.
Here’s the core gcc command, and it’s simpler than it sounds: gcc hello.c -o hello. Let’s break that down, because every part matters. gcc is the main command that runs the compiler. hello.c is the file you want to compile. The -o flag stands for “output”, and hello is the name of the final executable file – that’s the thing you’ll actually run. When you hit enter, gcc will do its thing. If you get no output at all? That means it worked. If it spits out red text (or whatever your terminal’s error color is), that means you messed up the code – maybe a missing semicolon, or a typo in printf. Don’t panic, that’s just gcc telling you where to fix it.
Once it’s done, run the program by typing ./hello and hitting enter. You’ll see that line: Hello from gcc on my terminal! That’s it – you just compiled and ran your first program with gcc. Cool, right?
Now, let’s talk about common flags you’ll actually use, because plain gcc hello.c works for simple stuff, but once you’re writing bigger code, you’ll want these. Let’s start with -Wall. That flag stands for “all warnings”, and it makes gcc point out little mistakes that might not break your code now, but will blow up on you later. For example, if you declare a variable you never use, gcc will warn you with -Wall, which saves you hours of debugging. I can’t tell you how many times a simple -Wall warning has caught a bug I missed while rushing to finish a project.
Next, -g. That adds debug info to your executable, so if your program crashes, you can use a tool like gdb (also included in build-essential) to track down exactly where it went wrong. If you’re a beginner, you might not need this right away, but once you’re writing anything more than a few lines, it’s a lifesaver.
Then there’s -O2, that’s an optimization flag. It tells gcc to make your executable run as fast as possible. For tiny programs, you won’t notice a difference, but for big projects – like games, data processing scripts, or even our own terminal firmware (we won’t brag, but it works thanks to similar tools) – -O2 can make your code run way smoother.
Wait, what if you have multiple files? Like, if you split your code into math.c, main.c, and utils.c, instead of compiling them all at once (which works, but is wasteful), you can compile them separately. First, type gcc -c math.c -o math.o, do the same for the others: gcc -c main.c -o main.o, gcc -c utils.c -o utils.o. The -c flag tells gcc to compile the code into an object file (the .o files) without linking them together. Then, link them all into one executable: gcc math.o main.o utils.o -o my_program. That’s way better for big projects, because if you only change math.c, you don’t have to recompile all the other files – just the modified one, which saves a ton of time. And yeah, our terminals have enough processing power and RAM to handle even really big projects with multiple files, no lag during compile time.
Now, let’s talk about common mistakes and how to fix them, because everyone messes these up. First, “permission denied” errors. If you try to run ./hello and get that, it means the executable doesn’t have permission to run. Just type chmod +x hello, and that fixes it. Super simple. Second, “no such file or directory” when you try to compile. That’s usually because you’re not in the right folder. Type ls to see your files, or cd Documents (or whatever folder your code is in) to navigate there. Third, “undefined reference to [something]” – that’s a linking error. That means you forgot to include one of your object files when you linked, like if you had a function in math.o and didn’t add it to the link command. Just double-check that you added all the .o files.
A quick pro tip from us at [my terminal supply company] – our terminals have a handy built-in split terminal feature that lets you have 2 or 3 sessions open at once. One window can be for editing code in nano, one for compiling with gcc, one for debugging with gdb. No more flipping between tabs, no more closing and reopening windows, which is perfect for when you’re in the zone and don’t want to break your flow. We built that feature specifically for devs who spend all day in the terminal, because wasting time switching screens is the worst.
Wait, what about C++? A lot of people ask, because gcc works for C++, too, you just use g++ instead of gcc. So if your file is hello.cpp, the command is g++ hello.cpp -o hello_cpp, same flags apply. That’s it, no extra hoops.
Let’s wrap this up with a little real example, because I hate when tutorials just throw commands at you. Let’s say you want to make a program that adds two numbers. Write this code:
#include
int main() {
int a = 5;
int b = 3;
int sum = a + b;
std::cout << "The sum is: " << sum << std::endl;
return 0;
}
Save it as add.cpp. Compile with g++ add.cpp -o add, run with ./add. Boom, it works. If you added -Wall and got a warning? Maybe you typed int a = 5; int b = 3; and never used one? No, this one’s fine, but if you did, -Wall would flag it to make sure you didn’t make a typo and accidentally name a variable wrong.
Now, if you’re tired of using flimsy laptops that die mid-compile, or terminals that lag when you run multiple tools, our gear is built for this exact workflow. We supply rugged, long-lasting terminals that handle all-day coding sessions, no lag, no random shutdowns, enough ports to plug in external drives or monitors, and all the tools you need to run gcc, g++, gdb, and everything else right out of the box. If you’re a student, indie dev, or even a small team looking to upgrade your setup, reach out to us to chat about your needs – we’ll help you pick the terminal that works best for your projects.
Before I go, let’s recap to make sure you didn’t miss anything: 1) Install gcc with your OS’s package manager, 2) Test it with gcc –version, 3) Write your code and save it with the right extension, 4) Use gcc (or g++ for C++) with flags like -Wall, -o, and -g to compile, 5) Run your executable with ./[output name]. It’s really that simple, and once you get the hang of it, you’ll wonder why you ever messed around with IDEs that hide all this stuff.

References:
- GNU Compiler Collection (GCC) Official Documentation
- The Linux Command Line: A Complete Introduction by William E. Shotts Jr.
- Ubuntu Official Package Manager Documentation
Neutral Boxes Wait, that’s all? Yeah, that’s the basics. No fancy stuff, no confusing terms, just how to use gcc in a terminal, with a little nod to why our terminals make this way easier. If you have questions about compiling, or need help picking the right terminal for your coding workflow, hit us up to connect and chat.
Hangzhou Lingcheng Technology Co., Ltd.
Address: Room 1613, 16th Floor, Building 3, No. 99 Wangzhou Road, Liangzhu Street, Yuhang District, Hangzhou City, Zhejiang Province
E-mail: LCKJ0408@163.com
WebSite: https://www.lingchengelectric.com/