Ubuntu

How to Install GCC in Ubuntu 22.04

Linux is a community-developed open-source software that provides compilers for many programming languages. The GNU is a collection of compilers, also known as GCC, which is a system compiler that is created to support the various scripting languages. It serves as the default compiler for the majority of GNU and Linux-related projects as well as the Linux kernel. The programming languages like C, C++, D, Fortran, Go and Ada need the GCC compiler for the execution of the code. The GCC is an open-source software that was created by the organization known as the Free Software Foundation (FSF).

The build-essential package is necessary for the GCC compiler. They contain the GNU debugger, the G++/GNU compiler collection, as well as the other tools and libraries that are required for the compilation of the program. We will describe how to install and utilize the GCC compiler on the Ubuntu server in the remaining section of the article. All commands inside the terminal used in this manual are run in an Ubuntu 22.04 system.

How to Install GCC in Ubuntu 22.04

We provided the step-by-step guidelines for the installation of GCC compiler on the most recent version of Ubuntu which is the Ubuntu 22.04. Let’s follow each step to install the GCC successfully.

Step 1: Update and Upgrade the System

Open the terminal of Ubuntu 22.04 by pressing the “ctrl+alt+t” key. Enter the apt command to update and upgrade the system dependencies and packages. The apt command uses the prefix “sudo” which enhances the privileges of the program. The sudo prefix allows the existing user to execute the specified command with the required permission as a super user in the Linux server. The “apt update” command determines the latest packages and dependencies versions. Whereas the “apt upgrade” upgrades the system packages to the most recent version by comparing the versions of each item in the list that we updated via “apt update”. We used both commands simultaneously with the -y flag which is assumed as “yes”. When the apt command is executed, the password is required for the username. Then, we can see the dependencies and packages build with the done statement.

Step 2: Install the GCC Compiler

Now, we have to install the GCC compiler with the build-essential meta-packages. The installation of the build-essential meta-packages is possible using the Ubuntu official repository. The default system repository for Ubuntu 22.04 contains these packages. The meta-packages of the required build tools are installed using the apt package manager. This build-essential package contains the GCC compiler, debugger, and other development libraries. The following command installs GCC in Ubuntu LTS 22.04:

After building the GCC dependencies and additional packages, the prompt asks a permission to continue the installation of GCC. Enter the keyword “Y” for further installation. Entering “N” is assumed as “No” and cancels the installation.

Step 3: Verify the Version of GCC Compiler

Once the installation of the GCC compiler is completed, check the version of the GCC that is installed in Ubuntu 22.04. Use the “gcc” prefix with the “–version” command. The version of GCC is displayed in the Ubuntu 22.04 shell.

Step 4: Install the GCC Manual Page

Since we installed the GCC compiler in our Ubuntu 22.04 system, we also checkwith the version command whether GCC is successfully installed or not. Note that we can also install the documentation page of GCC in our system for using its libraries and how it supports our system. We have to follow the following command to install the GCC documentation pages for any further help for development.

Step 5: Create a GCC Program

All the steps for the installation of the GCC compiler are accomplished. Now, we implement the C program to check the working of the GCC compiler. We create the file “MyFile” and assign the extension “.c” as it is a C program. Inside the “MyFile.c”, we use the C program library “stdio.h” with the prefix “#include” which is supported by the GCC compiler. This library is the header file for the default input and output of the C program.

It includes the data relating to input and output functions. Then, we define the int main function for the program to be executed. We call the printf function of the C scripting language that is used to print the statement placed inside it. We state the brackets of the printf function. Lastly, we use the “return 0” in our code which indicates that the code is executed successfully and achieved its objective.

Step 6: Compilation of a GCC Program

Now, it’s time to compile the previous C program with our GCC compiler. We launch the Ubuntu 22.04 terminal and use the GCC as a prefix. Then, we use the -o flag with the file and define the file name with the “c” extension. Before running the following command, we have to ensure that the file is located in the home directory. Otherwise, we need to specify the file path in the terminal.

Now, the “MyFile.c” is executable by running the previous command. We utilize the following command to execute the “MyFile.c” in the terminal.

We successfully printed the statement of the C program with the help of the GCC compiler. As the C program statement is displayed in the terminal of Ubuntu 22.04.

Conclusion

This guide gives a detailed instruction for the installation of the GCC compiler in the Ubuntu 22.04 system. For the installation of the GCC compiler, we utilized the build-essential on an Ubuntu 22.04 system which is covered in detail. We can use the aforementioned steps for the GCC compiler to be installed in our system. These commands are compatible with every Ubuntu version, but we used the Ubuntu 22.04 system. Then, we used the GCC version command to validate the successful installation of the compiler. In the end, we executed the C program with the GCC command.

 

Similar Posts