Or copy link
Copy link
GCC (GNU Compiler Collection) is a widely used compiler system that supports various programming languages, including C, C++, Objective-C, Fortran, Ada, and Go. It is a fundamental tool for Linux developers allowing them to compile and link their source code into executable programs.
In this post, we will cover the process steps involved in installing GCC on different Linux distributions.
Before we start to install GCC Linux process let’s briefly understand what is GCC compiler. It’s a suite of compilers, not a single compiler. Each language has its own compiler within the GCC suite. When you compile your code using GCC it goes through several stages:
The exact steps for GCC compiler installation may vary slightly depending on the Linux distribution you are using. Here are the instructions for some common distributions:
To update the package list on Ubuntu or Debian system use the following command:
sudo apt update
Then install the GCC with the help of the following command:
sudo apt install gcc
To install GCC for a specific language for example C++ use the following:
sudo apt install g++
To update the package list on the Fedora system use the following command:
sudo dnf update
sudo dnf install gcc
sudo pacman -Syu
sudo pacman -S gcc
First, install or enable the EPEL repository if not already enabled:
sudo yum install epel-release
To update the package list on CentOS or RHEL system use the following command:
sudo yum update
sudo yum install gcc
If you are using a less common distribution refer to its package manager for specific GCC compiler Linux download. The general approach is usually similar involving updating package lists and installing the GCC package.
To verify that GCC is installed correctly you can check its version:
gcc --version
This will output the installed GCC version.
Install GCC Compiler on Our Linux VPS today!
Ultahost offers Linux hosting with NVMe SSD storage. Use our Linux VPS to practice the command and streamline your processes.
Once you have successfully installed GCC on your Linux system you can start using it to compile your C/C++ programs. Here’s a basic overview of the GCC command and some common usage scenarios:
The general syntax for using GCC is:
gcc [options] files
To compile a single C file named hello.c into an executable named hello you would use:
hello.c
hello
gcc hello.c -o hello
The -o option specifies the output filename.
-o
To compile multiple C files for example main.c and utils.c into a single executable:
main.c
utils.c
gcc main.c utils.c -o myprogram
If your program uses external libraries you need to link them during compilation. For example, to link with the math library:
math
gcc myprogram.c -o myprogram -lm
The -lm flag links with the math library.
-lm
To compile your program with debugging symbols for use with GDB:
gcc -g myprogram.c -o myprogram
Then, you can use GDB to debug the executable:
gdb myprogram
To enable optimizations for example for performance:
gcc -O2 myprogram.c -o myprogram
The -O2 flag enables level 2 optimizations.
-O2
Read also How to use Linux Shutdown Command.
Following are the important notes while installing the GCC Compiler on a Linux system:
math.h
GCC is a powerful and versatile compiler suite that plays an important role in the development of C, C++, and other programming languages on Linux systems. By following the steps outlined in this guide you should be able to successfully install and use GCC to compile and build your projects.
Install GCC Compiler on Linux is a simple process depending on different Linux enviourment. For a more robust and flexible environment consider Ultahost’s cheap VDS hosting which provides dedicated resources and optimal performance ideal for managing advanced process tasks.
GCC is a compiler for C, C++, and other languages on Linux.
GCC is needed to compile and build programs from source code
Run the command gcc –version in your terminal.
Use the command sudo apt-get install gcc in your terminal.
No, you may need to install it manually on some distributions.
You need admin sudo rights to install GCC using package managers.
Use your package manager like sudo apt-get upgrade gcc on Ubuntu.
When you are a Linux user, few tools commands are as po...
The .deb packages are the standard format for installin...
Objective-C is a powerful programming language often as...
Visual Studio Code (VS Code) is a widely used code edit...
ulimit stands for "user limits" and is used to set or d...
When a Windows user switches to Linux the first thing i...
Save my name, email, and website in this browser for the next time I comment.
Δ