The GNU Compiler Collection (GCC) is an open-source collection of compilers and libraries supporting C, C , Objective-C, Fortran, Ada, Go, and D programming languages. The Linux kernel, the GNU utilities, and many other projects are compiled with GCC.

This tutorial explains how to install the GCC compiler on Debian 10, Buster. The same instructions apply for Debian 9 and any Debian-based distribution.

Prerequisites

To install packages on your Debian system, you must be logged in as a user with sudo privileges.

Installing GCC on Debian

The default Debian repositories contain a meta-package named build-essential that contains the GCC compiler and other libraries and utilities required for compiling software.

Follow the steps below to install the GCC Compiler Debian 10:

  1. First, update the packages list:
    sudo apt update
  2. Install the build-essential package by running:
    sudo apt install build-essential

    You may also want to install the manual pages that includes documentation about using GNU/Linux for development:

    sudo apt-get install manpages-dev
  3. To confirm that the GCC compiler is successfully installed type gcc --version:
    gcc --version

    At the time of writing this article, the default version of GCC available in the Debian 10 repositories is 8.3.0:

    gcc (Debian 8.3.0-6) 8.3.0
    Copyright (C) 2018 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.

That’s it. You have successfully installed GCC on your Debian machine.

Compiling a Hello World Example

Compiling a basic C or C program with GCC is pretty straightforward. Open your text editor and create the following file:

nano hello.c

hello.c

#include 
int main()
{
  printf ("Hello World!n");
  return 0;
}

Save the file and use the following command to compile it into an executable:

gcc hello.c -o hello

The compiler will create a binary file named hello in the same directory, where the command was executed.

To execute the program run:

./hello

The output will look like this:

Hello World!

Conclusion

You have successfully installed GCC on your Debian 10. For more information about GCC, visit the official GCC Documentation.

If you hit a problem or have feedback, leave a comment below.