In this tutorial, we will show you how to install GCC on Debian 11. For those of you who didn’t know, GCC, which stands for GNU Compiler Collection, is a powerful and versatile compiler system that plays a crucial role in programming and development on Debian-based systems. As an essential tool for compiling C, C++, and other programming languages, GCC is a must-have for any developer working on Debian 11.
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 through the step-by-step installation of GCC Compiler on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 11.
- 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).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install GCC on Debian 11 Bullseye
Step 1. To guarantee a smooth installation process, it’s crucial to update your system to the latest stable version. Open a terminal and run the following commands:
sudo apt update sudo apt upgrade
These commands will fetch the latest package lists from the repositories and upgrade any outdated packages to their newest versions. Having an up-to-date system not only ensures compatibility with GCC but also helps maintain the security and stability of your Debian 11 installation.
Step 2. Installing GCC on Debian 11.
The simplest and most straightforward way to install GCC on Debian 11 is by using the build-essential package. This meta-package includes not only GCC but also G++ (the C++ compiler) and other essential development tools like make. To install build-essential, run the following command:
sudo apt install build-essential
Enter your sudo password when prompted and confirm the installation by pressing ‘Y’ when asked. The package manager will now download and install GCC, G++, and the required dependencies.
Once the installation is complete, you can verify that GCC is successfully installed by checking its version. Run the following command:
gcc --version
Step 3. Compiling Hello World Using GCC.
Once successfully installed, now we create a basic C code source, for example: let’s create a hello world C program and open hello.c text file:
nano hello.c
Add the following line:
// hello.c #include int main() { printf("Hello, world!\n"); return 0; }
Save and close, then compile it and execute the hello program by running the following command below:
gcc hello.c -o hello ./hello
Output:
root@idroot.us:~# ./hello Hello, world!
Congratulations! You have successfully installed GCC. Thanks for using this tutorial for installing the latest version of GCC Compiler on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official GCC website.