How to Install GCC Compiler on Ubuntu

Author - Sanjay
Introduction
In this guide, I'll go over how to install GCC compiler on Ubuntu. There are multiple programming languages and many different compilers available. If you're just getting into programming and don't know what a compiler is, look it up. But if you already know what a compiler is and want a quick rundown of installing one in Ubuntu, keep reading.
Table of Contents
Pre-Requisistes
A Ubuntu 22.10 server or a Desktop with root privilages.
Install GCC on UBUNTU Step By Step
- Lets start the first step by updating our pacakge repo .
$thelinux $ sudo apt-get update
- Next step is to install the build-essential package using below command
$thelinux $ sudo apt install build-essential
This command as shown above installs a bunch of new packages including gcc, g++ and make , it comes prepackaged in most of linux repo .
- Now Install Manual Pages , Although its optional
sudo apt-get install manpages-dev
- Check the Gcc Version
$ gcc --version
Step by Step Guide to Execute Simple C Program Using GCC
- First step is create a C file by executing below command
thelinuxt$ sudo vi hello.c
This will open a text editor, where you can write your C/C++ program and save in it. Check if your file hello.c has the permission to execute using the command:
- Next step is to compile your program using the following command .
gcc hello.c -o hello
- Last step is to execute the program as shown below
./hello
Installing Multiple GCC Versions in Ubuntu
- Lets first add the ubuntu-toolchain-r/test PPA to our system using below command.
thelinuxt $ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
- Next step install the desired GCC and G++ versions as shown below , We will install gcc version 9,10 and 11.
thelinuxt $ sudo apt install gcc-9 g++-9 gcc-10 g++-10 gcc-11 g++-11
Conclusion
We have done GCC installation on our Ubuntu system . We have also seen how we can write a program and Compile a C program using GCC. If you face and difficulty or any problem , let us know on comments.