How to Install GCC C/C++ Compiler on Debian 12

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”.

  1. Updating the Debian 12 Package Database Cache
  2. Installing the GCC C/C++ Compiler on Debian 12
  3. Testing If the GCC Compiler Is Installed Correctly on Debian 12
  4. Installing the Older Version of the GCC C/C++ Compiler on Debian 12
  5. 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.

A screenshot of a computer Description automatically generated

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>.

A screenshot of a computer Description automatically generated

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

A screenshot of a computer Description automatically generated

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

A screenshot of a computer Description automatically generated

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

A screenshot of a computer Description automatically generated

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.

A screenshot of a computer Description automatically generated

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>.

A screenshot of a computer Description automatically generated

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

A screenshot of a computer Description automatically generated

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

A screenshot of a computer Description automatically generated

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

A screenshot of a computer program Description automatically generated

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

$ gcc –version

$ g++ –version

A screenshot of a computer Description automatically generated

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.

source

Leave a Comment