GNU Compiler Collection or GCC is a collection of open-source compilers and toolsets that are developed by the GNU project. The GCC compiler can compile the source codes of C/C++, Objective-C, Fortran, and other programming languages into the machine code. GCC also provides code optimization and error checking of the source code during the compilation process as well as the necessary tools to debug the compiled programs. It can also compile the source codes for different system architectures like ARM 32-bit, ARM 64-bit, x86_64, PowerPC, etc.
In this article, we will show you how to install the GCC C/C++ compiler on Debian 12 “Bookworm”.
Topic of Contents:
- Updating the Debian 12 Package Database Cache
- Installing the GCC C/C++ Compiler on Debian 12
- Testing If the GCC Compiler Is Installed Correctly on Debian 12
- Installing the Older Version of the GCC C/C++ Compiler on Debian 12
- Conclusion
Updating the Debian 12 Package Database Cache
To update the Debian 12 package database cache, run the following command:
The Debian 12 package database cache should be updated.

Installing the GCC C/C++ Compiler on Debian 12
To install the GCC C/C++ compiler and the necessary build tools on Debian 12, run the following command:
$ sudo apt install build-essential
To confirm the installation, press Y and then press <Enter>.

GCC and the necessary build tools are being downloaded from the internet. It takes a while to complete.

GCC and the necessary build tools are being installed. It takes a while to complete.

At this point, the GCC C/C++ compiler and the necessary build tools should be installed on your Debian 12 machine.

Testing If the GCC Compiler Is Installed Correctly on Debian 12
Once the GCC C/C++ compiler is installed, you can run the following commands from a terminal to check whether you can access them:
$ gcc --version
$ g++ --version
As you can see, the GCC C/C++ compiler version 12.2.0 is installed on our Debian 12 machine.

Installing the Older Version of the GCC C/C++ Compiler on Debian 12
Debian 12 installs the GCC C/C++ compiler version 12 by default. If you need an older version of the GCC C/C++ compiler, you can install the GCC C/C++ compiler version 11 on your Debian 12 machine.
To install the GCC C/C++ compiler version 11 on Debian 12, run the following command:
$ sudo apt install gcc-11 g++-11
To confirm the installation, press Y and then press <Enter>.

The GCC C/C++ compiler version 11 and the necessary build tools are being downloaded from the internet. It takes a while to complete.

The GCC C/C++ compiler version 11 and the necessary build tools are being installed. It takes a while to complete.

At this point, the GCC C/C++ compiler version 11 should be installed on your Debian 12 machine.

As you can see, the GCC C/C++ compiler version 11.3.0 is installed on our Debian 12 machine.
$ gcc --version
$ g++ --version

Conclusion
We showed you how to install the GCC C/C++ compiler version 12 on Debian 12. We also showed you how to install the GCC C/C++ compiler version 11 on Debian 12.
About the author
Shahriar Shovon
Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.