Installing GCC on Debian 12

Hello,

In this week’s feature highlight, we look at How to Install GCC on Debian 12

GCC, the GNU Compiler Collection is a compiler system developed to support various programming languages. GCC is the standard compiler for most projects related to GNU and Linux, including the Linux kernel.

Installing GCC on Debian

Debian repositories contain build-essential package which contains the GCC compiler, g++ and make

Debian an existing system by running following command

apt upgrade 

apt install build-essential

If you want to install the manual page for GCC, run the below command,

apt-get install manpages-dev

After installing, to verify that GCC is successfully installed by checking gcc version,

gcc --version

Output:

 root@server:~# gcc --version
 gcc (Debian 12.2.0-14) 12.2.0
 Copyright (C) 2022 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@server:~#

Compiling a Hello World Example

Create a basic C code source, eg: let’s create a hello world C program and open hello.c text file,

nano hello.c

Add the following code to hello.c file

// hello.c
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}

Compile it into an executable and execute the hello program by running the following commands,

gcc hello.c -o hello

./hello

Output:

root@server:~# ./hello 
Hello, world!
(Visited 234 times, 1 visits today)