How to Compile and Execute C Programs on Linux

Learn how to use the GCC compiler to build and run C programs on a Linux system. This essential skill will enable you to develop and test your applications effortlessly on any Linux distribution, such as the latest Ubuntu.

A Comprehensive Guide to Compile C Programs on Linux

Step 1: Installing the Necessary Build Tools

Firstly, before you start compiling C programs, ensure that your Linux system is equipped with the necessary development tools. Install the ‘build-essential’ package by executing:

$ sudo apt-get install build-essential

This command requires root access, so enter your password to proceed. Stay connected to the internet until the installation finishes.

Step 2: Crafting Your First C Program

Once you have the necessary tools, it’s time to write your C program. Use a text editor available in Ubuntu to type or paste in your code. For instance:

#include <stdio.h>

int main() {printf("Hello, World! This is a sample C program.nn"); return 0;}

Save your code into a file with a “.c” extension, for example, ‘hello_world.c’, preferably in your home directory.

Step 3: Compiling the C Program with GCC

To compile your C program into an executable, use the GCC compiler with the following syntax:

$ gcc -o hello_world hello_world.c

Replace ‘hello_world.c’ with your file’s name. Ensure the file is at the location you’re currently in, or specify the correct path to the file.

Step 4: Executing Your C Program

Once compiled, run your program with:

$ ./hello_world

You should now see the output displayed in the terminal.

Understanding C Compilation on Linux: FAQs

What Is a C Compiler?

A C Compiler is a software tool that converts C source code into executable machine code that the computer can understand and execute.

What Are the Capabilities of GCC?

GNU Compiler Collection (GCC) is a robust compiler suite supporting languages such as C, C++, Objective-C, Fortran, Ada, and Go.

Why Is the ‘build-essential’ Package Required?

‘Build-essential’ provides key tools and libraries, such as the GCC compiler and ‘make’, crucial for building C programs on a Linux environment.

How Do I Ensure GCC Is Up to Date?

To check your GCC compiler version and potentially get an update, use:

gcc --version

sudo apt-get update && sudo apt-get install gcc


Mastering the compilation of C programs on Linux is a valuable skill for any programmer. With the GCC compiler and the steps outlined above, you’re well-equipped to bring your C programs to life on a Linux platform. Should you encounter any hitches or have questions, our community forum is always here to help.

Editorial Staff
Editorial Staff
The Bollyinside editorial staff is made up of tech experts with more than 10 years of experience Led by Sumit Chauhan. We started in 2014 and now Bollyinside is a leading tech resource, offering everything from product reviews and tech guides to marketing tips. Think of us as your go-to tech encyclopedia!


Please enter your comment!
Please enter your name here

Related Articles

Best Telemedicine Software: for your healthcare practice

Telemedicine software has transformed my healthcare visits. It's fantastic for patients and doctors since they can obtain aid quickly. I...
Read more
I love microlearning Platforms in today's fast-paced world. Short, focused teachings that engage me are key. Microlearning platforms are great...
Think of a notebook on your computer or tablet that can be changed to fit whatever you want to write...
As of late, Homeschool Apps has gained a lot of popularity, which means that an increasing number of...
From what I've seen, HelpDesk software is essential for modern businesses to run easily. It's especially useful for improving customer...
For all of our important pictures, stories, and drawings, Google Drive is like a big toy box. But sometimes the...