How to Install GCC on Ubuntu 22.04

The full form of GCC is GNU Compiler Collection. It is an open source toolset for compiling source codes of C, C++, Objective-C, Fortran, Ada, Go and D programming languages. In this article, I am going to show you how to install GCC on Ubuntu and compile C and C++ programs.

In this tutorial, i am going to show you how to install and Use GCC compiler on Linux ubuntu 22.04 system.

How to Install GCC on Ubuntu 22.04

Follow the below given steps to install GCC on the ubuntu 22.04 system:

  • Step 1 – Update System Dependencies
  • Step 2 – Install GCC
  • Step 3 – Verify GCC Installation
  • Step 4 – Create a C program in Run In GCC

Step 1 – Update System Dependencies

First of all, run the following command on command line or terminal to update system dependencies:

sudo apt update

Step 2 – Install GCC

Then install gcc in ubuntu system using running following command:

sudo apt install build-essential

Step 3 – Verify GCC Installation

Run the following command on command line to verify gcc installation on ubuntu system:

gcc --version

Step 4 – Create a C program in Run In GCC

Once the gcc installation has been done, Then create a simple hello world C program in nano editor and saved the file as helloworld.c.

#include <stdio.h>
int main() {
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}

Save this file and convert this into an executable one.

gcc -o helloworld helloworld.c

The above given command will generate a binary file by the name “helloworld” in the same directory. Execute the program using the following command on command line:

./helloworld

The C program was executed successfully.

Conclusion

In this tutorial, i have shown to you how to install and Use the GCC compiler on Linux ubuntu 22.04 system.

Be First to Comment

Leave a Reply

Your email address will not be published.