Quickly Compile Your 1st C Program

Getting started with C programming on Linux only requires one package: gcc

Once you do that, you’re off to the races! 😁

Summary of Commands:

# Install GNU Compiler Collection (gcc)
sudo apt -y install gcc
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gcc is already the newest version (4:13.2.0-7ubuntu1).
The following packages were automatically installed and are no longer required:
  libdrm-nouveau2 libdrm-radeon1 libgl1-amber-dri libglapi-mesa libllvm17t64 libwayland-server0
  libxcb-dri2-0
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 38 not upgraded.

# Create Source Code
vim hello.c

# Compile source code 'hello.c' and 
# name executable 'hw'
gcc hello.c -o hw

# Run executable 'hw'
./hw

Source Code for ‘hello.c’

hello.c
#include<stdio.h>
int main(){
printf("Hello world!\n");
return 0;
}

Demo

Leave a comment