{"id":3624,"date":"2026-10-22T01:51:51","date_gmt":"2026-10-21T17:51:51","guid":{"rendered":"http:\/\/www.zeyumixer.com\/blog\/?p=3624"},"modified":"2026-10-22T01:51:51","modified_gmt":"2026-10-21T17:51:51","slug":"how-to-use-the-gcc-compiler-in-a-terminal-4b73-76576f","status":"publish","type":"post","link":"http:\/\/www.zeyumixer.com\/blog\/2026\/10\/22\/how-to-use-the-gcc-compiler-in-a-terminal-4b73-76576f\/","title":{"rendered":"How to use the gcc compiler in a terminal?"},"content":{"rendered":"<p>Hey everyone, I\u2019m Jake from [my terminal supply company \u2013 no name drop, just keep it natural], and if you\u2019ve ever stared at a blank terminal window wondering how to turn that random code you scribbled into actual working software, this post\u2019s for you. For months, I\u2019ve been sending our rugged, workhorse terminals to devs, students, and even indie game makers, and one question comes up more than any other: \u201cHow do I actually use gcc in a terminal?\u201d Today, I\u2019m breaking this down like I would to a new intern who\u2019s 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. <a href=\"https:\/\/www.lingchengelectric.com\/terminal\/\">Terminal<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.lingchengelectric.com\/uploads\/48003\/small\/twenty-four-circuit-repeatable-grounding-box6119c.png\"><\/p>\n<p>First, let\u2019s get one thing straight: gcc isn\u2019t some magic black box. It\u2019s just a compiler \u2013 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\u2019re running 10 other tools at once), you\u2019ll never have that frustrating moment where your session locks up right as your code\u2019s about to work. But enough about our gear for now \u2013 let\u2019s dive into the actual steps.<\/p>\n<p>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 \u201ccommand not found\u201d error, and that\u2019s because some OSes don\u2019t include gcc by default. Let\u2019s fix that first. If you\u2019re on Ubuntu, Debian, or any Debian-based Linux, just fire off this command: sudo apt update &amp;&amp; sudo apt install build-essential. That\u2019s it \u2013 build-essential grabs gcc and all the other little tools you\u2019ll need to compile code without extra headaches. If you\u2019re on Fedora or RHEL? Swap that out for sudo dnf group install &quot;Development Tools&quot;. For macOS? You\u2019ll need Xcode Command Line Tools \u2013 just type xcode-select &#8211;install, and it\u2019ll 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.<\/p>\n<p>Once gcc is installed, let\u2019s test it real quick to make sure it\u2019s working. Open your terminal (the same one from our gear, or any, but why not use the one that\u2019s built to handle this stuff?). Type gcc &#8211;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\u2019re golden. If not? Double-check your install command, and make sure you typed it right \u2013 typos happen to everyone, even me.<\/p>\n<p>Now, let\u2019s get to the fun part: actually compiling code. Let\u2019s say you wrote a super simple C program, like a \u201cHello World\u201d script. Open your favorite text editor (nano, vim, VS Code \u2013 all work perfectly on our terminals), type this code:<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\nint main() {<br \/>\nprintf(&quot;Hello from gcc on my terminal!\\n&quot;);<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>Save that file as hello.c. Pro tip: name it something descriptive, not code123.c \u2013 you\u2019ll thank yourself later when you have 20 files. Now, go back to your terminal, and make sure you\u2019re in the same folder where you saved hello.c. If you\u2019re lost, type ls to list all the files in your current directory \u2013 you should see hello.c pop up.<\/p>\n<p>Here\u2019s the core gcc command, and it\u2019s simpler than it sounds: gcc hello.c -o hello. Let\u2019s 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 \u201coutput\u201d, and hello is the name of the final executable file \u2013 that\u2019s the thing you\u2019ll 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\u2019s error color is), that means you messed up the code \u2013 maybe a missing semicolon, or a typo in printf. Don\u2019t panic, that\u2019s just gcc telling you where to fix it.<\/p>\n<p>Once it\u2019s done, run the program by typing .\/hello and hitting enter. You\u2019ll see that line: Hello from gcc on my terminal! That\u2019s it \u2013 you just compiled and ran your first program with gcc. Cool, right?<\/p>\n<p>Now, let\u2019s talk about common flags you\u2019ll actually use, because plain gcc hello.c works for simple stuff, but once you\u2019re writing bigger code, you\u2019ll want these. Let\u2019s start with -Wall. That flag stands for \u201call warnings\u201d, 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\u2019t tell you how many times a simple -Wall warning has caught a bug I missed while rushing to finish a project.<\/p>\n<p>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\u2019re a beginner, you might not need this right away, but once you\u2019re writing anything more than a few lines, it\u2019s a lifesaver.<\/p>\n<p>Then there\u2019s -O2, that\u2019s an optimization flag. It tells gcc to make your executable run as fast as possible. For tiny programs, you won\u2019t notice a difference, but for big projects \u2013 like games, data processing scripts, or even our own terminal firmware (we won\u2019t brag, but it works thanks to similar tools) \u2013 -O2 can make your code run way smoother.<\/p>\n<p>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\u2019s way better for big projects, because if you only change math.c, you don\u2019t have to recompile all the other files \u2013 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.<\/p>\n<p>Now, let\u2019s talk about common mistakes and how to fix them, because everyone messes these up. First, \u201cpermission denied\u201d errors. If you try to run .\/hello and get that, it means the executable doesn\u2019t have permission to run. Just type chmod +x hello, and that fixes it. Super simple. Second, \u201cno such file or directory\u201d when you try to compile. That\u2019s usually because you\u2019re 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, \u201cundefined reference to [something]\u201d \u2013 that\u2019s 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\u2019t add it to the link command. Just double-check that you added all the .o files.<\/p>\n<p>A quick pro tip from us at [my terminal supply company] \u2013 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\u2019re in the zone and don\u2019t 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.<\/p>\n<p>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\u2019s it, no extra hoops.<\/p>\n<p>Let\u2019s wrap this up with a little real example, because I hate when tutorials just throw commands at you. Let\u2019s say you want to make a program that adds two numbers. Write this code:<\/p>\n<p>#include <iostream><br \/>\nint main() {<br \/>\nint a = 5;<br \/>\nint b = 3;<br \/>\nint sum = a + b;<br \/>\nstd::cout &lt;&lt; &quot;The sum is: &quot; &lt;&lt; sum &lt;&lt; std::endl;<br \/>\nreturn 0;<br \/>\n}<\/p>\n<p>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\u2019s fine, but if you did, -Wall would flag it to make sure you didn\u2019t make a typo and accidentally name a variable wrong.<\/p>\n<p>Now, if you\u2019re 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\u2019re a student, indie dev, or even a small team looking to upgrade your setup, reach out to us to chat about your needs \u2013 we\u2019ll help you pick the terminal that works best for your projects.<\/p>\n<p>Before I go, let\u2019s recap to make sure you didn\u2019t miss anything: 1) Install gcc with your OS\u2019s package manager, 2) Test it with gcc &#8211;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\u2019s really that simple, and once you get the hang of it, you\u2019ll wonder why you ever messed around with IDEs that hide all this stuff.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.lingchengelectric.com\/uploads\/48003\/small\/three-phase-ct-interference-connector-6a4f2a4.png\"><\/p>\n<p>References:<\/p>\n<ol>\n<li>GNU Compiler Collection (GCC) Official Documentation<\/li>\n<li>The Linux Command Line: A Complete Introduction by William E. Shotts Jr.<\/li>\n<li>Ubuntu Official Package Manager Documentation<\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.lingchengelectric.com\/metering-junction-boxes\/neutral-boxes\/\">Neutral Boxes<\/a> Wait, that\u2019s all? Yeah, that\u2019s 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.<\/p>\n<hr>\n<p><a href=\"https:\/\/www.lingchengelectric.com\/\">Hangzhou Lingcheng Technology Co., Ltd.<\/a><\/p>\n<p>Address: Room 1613, 16th Floor, Building 3, No. 99 Wangzhou Road, Liangzhu Street, Yuhang District, Hangzhou City, Zhejiang Province<br \/>E-mail: LCKJ0408@163.com<br \/>WebSite: <a href=\"https:\/\/www.lingchengelectric.com\/\">https:\/\/www.lingchengelectric.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey everyone, I\u2019m Jake from [my terminal supply company \u2013 no name drop, just keep it &hellip; <a title=\"How to use the gcc compiler in a terminal?\" class=\"hm-read-more\" href=\"http:\/\/www.zeyumixer.com\/blog\/2026\/10\/22\/how-to-use-the-gcc-compiler-in-a-terminal-4b73-76576f\/\"><span class=\"screen-reader-text\">How to use the gcc compiler in a terminal?<\/span>Read more<\/a><\/p>\n","protected":false},"author":155,"featured_media":3624,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3587],"class_list":["post-3624","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-terminal-4bf0-7692eb"],"_links":{"self":[{"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/posts\/3624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/users\/155"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/comments?post=3624"}],"version-history":[{"count":0,"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/posts\/3624\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/posts\/3624"}],"wp:attachment":[{"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/media?parent=3624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/categories?post=3624"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zeyumixer.com\/blog\/wp-json\/wp\/v2\/tags?post=3624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}