Compiling and Running C program on Linux Mint

C is a general-purpose, object-oriented and compiled programming language. The C programming language is the most popular programming language that can be used in a variety of application field including system programming, software programming like desktop and mobile app development, etc.

Compile and Run C Program on Linux

You may want to write, compile and run C program on your Linux Mint or any Mint like Linux distro, for example, Ubuntu, Debian, etc. As we know C is a compiled language so, first of all, we need a C compiler for compiling our source code.

The compiler also helps to run or execute the output of the compiled binary code. And obviously, we need a text editor to write our code.

GNU C Compiler is the most popular, widely used and ultimate portable C compiler for the Linux operating system. So before working with C programs, we need to install GCC compiler on our system. If you already have installed on your system then let’s go to the next step. If you don’t have installed yet, follow the link below;

Recommended: How to Install GCC – GNU C Compiler on Linux

Program We will Run

In this tutorial, we will run a simple Hello World program in C. Open up a text editor like gedit (To open gedit go to your terminal and type gedit and then press enter) and write down the following code and then save the file as helloworld.c in your desktop folder.

#include <stdio.h>
int main() {
    printf("Hello, World!\n");
    return 0;


Make sure you have saved the file at your desktop and also make sure the file name extension in .c

Using Command Line

In the previous step, we have created our Hello World C program at the desktop as helloworld.c. Now we will compile and run the program using the command line.

To compile and run with the command line:

  1. First, open up your terminal and write gcc -o helloworld helloworld.c. This command will compile the code and create an object file. You can notice the object file on your desktop. Notice that a new file has been created It is actually compiled object file.
  2. Now we can run this by using ./helloworld command like the image below. The output Hello, World! should be executed.
    compile and run C program on linux command line
  3. Notice that on line three. The Hello, World! message has been executed.

Using Text Editor: Sublime Text

To run using Sublime text editor, first, make sure sublime text editor is already installed on your system. Then open the C program file that you have created in the first step. Then simply click on the Tools menu and then build sub-menu to build/compile the program. Finally, click on the build with the run to execute the program.

compile and run C program on linux using Sublime Text

The executed result will be shown at the bottom window with build time like the image above.


You can use any text editor or IDE to edit, compile and run your c program. For all the system the compiler works almost the same mechanism.

{Linux & C case studies}

Linux Tutorial C Tutorial Linux Tutorial Index

Posted in