DebianDebian Based

How To Install GCC (GNU Compiler Collection) on Debian 12

Install GCC on Debian 12

In this tutorial, we will show you how to install GCC (GNU Compiler Collection) on Debian 12. GCC, an essential part of the GNU toolchain, offers numerous advantages for developers. It is a versatile compiler that supports multiple programming languages, including C, C++, and Fortran. With its highly optimized code generation and extensive optimization options, GCC enhances the performance of your software. Additionally, GCC’s compatibility with various platforms and continuous improvements through community contributions make it a preferred choice for developers worldwide.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the GCC on a Debian 12 (Bookworm).

Prerequisites

  • A server running one of the following operating systems: Debian 12 (Bookworm).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for GCC.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install GCC on Debian 12 Bookworm

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt install apt-transport-https lsb-release ca-certificates

This command will refresh the repository, allowing you to install the latest versions of software packages.

Step 2. Installing GCC (GNU Compiler Collection) on Debian 12.

Now that your system is up to date let’s proceed with the installation of GCC on Debian 12 Bookworm. There are two recommended methods to install GCC: using the Official Debian Repository and building GCC from source. We’ll cover both methods to cater to different user preferences.

  • A. Method 1: Using the Official Debian Repository:

Installing GCC from the official Debian repository ensures compatibility and ease of maintenance within the Debian ecosystem. Follow these detailed steps to install GCC using this method:

sudo apt-add-repository "deb http://deb.debian.org/debian $(lsb_release -cs) main"

Update the package lists and install GCC using the following command:

sudo apt update
sudo apt install build-essential

Verify the installation:

gcc --version
  • B. Method 2: Building GCC from Source:

For advanced users who prefer customizability and access to the latest features, building GCC from a source is an option. Follow these steps to install GCC from the source:

wget ftp://ftp.gnu.org/gnu/gcc/gcc-{VERSION}/gcc-{VERSION}.tar.gz

Note: Replace {VERSION} with the desired version of GCC you wish to install.

Extract the source code:

tar xvf gcc-{VERSION}.tar.gz

Configure the build:

cd gcc-{VERSION}
./configure --prefix=/usr/local/gcc

Note: Adjust the prefix path (/usr/local/gcc) as per your preference.

Compile and install:

make -j$(nproc)
sudo make install

Verify the installation:

/usr/local/gcc/bin/gcc --version

To further validate the installation, you can compile a simple test program. Create a new file, such as test.c, and add the following code:

#include 

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

Save the file and compile it using the following command:

gcc test.c -o test

Finally, run the compiled program by executing:

./test

If the program prints “Hello, world!” to the terminal, GCC is functioning correctly on your Debian 12 Bookworm system.

Step 3. Troubleshooting Tips:

While installing GCC on Debian 12 Bookworm, you may encounter some common issues. Here are a few troubleshooting tips:

  1. Missing Dependencies: If you encounter dependency errors during the installation, ensure that you have enabled the necessary repositories and perform the updates again.
  2. Insufficient Disk Space: In case you run out of disk space during the installation process, consider cleaning up unnecessary files or expanding your storage.
  3. Build Errors: If you face errors while building GCC from the source, carefully review the error messages and consult relevant online resources or forums for assistance.

Congratulations! You have successfully installed GCC. Thanks for using this tutorial for installing the latest version of GCC on Debian 12 Bookworm. For additional help or useful information, we recommend you check the official GCC website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button