Ubuntu

How to install GCC on Ubuntu 22.04


GCC aka GNU Compiler Collection is a set of development tools and compilers. These compilers/tools can be used on platforms such as Windows, Linux, BSDs, and many other operating systems.

GCC can be used to compile many programming languages such as C, Objective C, C++, D, Go, Ada, and Fortran. This software is completely free and was originally developed by Free Software Foundation aka FSF.

Here we have guided you step-by-step on the procedure of installing GCC on the latest release of Ubuntu which is Ubuntu 22.04.

How to install GCC on Ubuntu 22.04

If you wish to install GCC on Ubuntu 22.04 then consult the guide provided below.

Step 1: Update the system

Before installing GCC, update your Ubuntu 22.04 by running the following command. This is done to make sure all the relevant packages are updated so that any conflict does not occur.

$ sudo apt update

Output

Step 2: Install GCC

Afterward, it is recommended to install the build-essential package that consists of packages of GCC and many other applications.

$ sudo apt install build-essential

Output

Step 3: Evaluate Installation

Now to verify the successful installation of GCC evaluate the C compiler version through the following command.

$ gcc --version

Output

Step 4: Create a C program

Once installed, verify if the compiler is working properly or not by creating a simple C program. For instance, below we have created a simple hello world C program in nano editor and saved the file as helloworld.c.

Save this file and convert this into an executable one.

$ gcc -o helloworld helloworld.c

This command will generate a binary file by the name “helloworld” in the same directory. Now you have to execute the program using the below-mentioned command.

$ ./helloworld

Output

The C program was executed successfully.

Voila! GCC has been successfully installed on Ubuntu 22.04.

Conclusion

For the purpose of installing GCC on Ubuntu 22.04, first update it by using the command $ sudo apt update then install the build-essential package that contains the GCC package through the command $ sudo apt install build-essential. Then use the $ gcc –version command to verify the successful installation of GCC. Lastly, make a simple C program and compile and execute this program using these commands; $ gcc -o filename filename.c, and $ ./filename.

About the author

Naima Aftab

I am a software engineering professional with a profound interest in writing. I am pursuing technical writing as my full-time career and sharing my knowledge through my words.