To compile and run a C program in Ubuntu, you need the GCC compiler, which is included in the build-essential package. After installing it, you can create, compile, and execute C programs directly from the terminal.
Step 1: Install GCC compiler on Ubuntu
- First, update your system and install the build-essential package:
sudo apt update
sudo apt install build-essential
Verify that GCC is installed:
gcc --version

Step 2: Create a C Program File
Use the touch command to create a new C source file:
touch hello.c
Step 3: Write a C Program
Open the file using a text editor such as Nano:
nano hello.c
Write a basic C program:
#include <stdio.h>
int main() {
printf("Hello world");
return 0;
}
Output
Hello world


Step 4: Compile the C Program
Compile the program using GCC:
gcc hello.c
This command generates an executable file named a.out by default.
To specify an output file name:
gcc hello.c -o hello

Step 5: Run the hello executable file
- Run the compiled program using:
./hello

Now, we can see the actual output of Hello World in our terminal of the hello.c system file.
Also Read