How To Install C Compiler In Ubuntu
Learn how to install C on Linux.
Overview
Linux is a set of open up-source UNIX-like operating systems, and Ubuntu is a Linux-based operating system ordinarily used to run Linux-based applications. To install C on Linux and to build and run our C program file on Ubuntu, we need to install the GCC Compiler. In Ubuntu repositories, GCC Compiler is a part of the build-essential parcel nosotros need to install.
We empathize that installing C on Linux might seem daunting, but don't worry; nosotros've got you covered with our footstep-by-step guide!
Scope of Article
In this article, we will see
- How to install C and GNU Compiler Collection (GCC Compiler) on Linux.
- How to compile and run a C Program in the Linux terminal.
Installing the GCC Compiler Using Terminal in Linux
GCC Compiler (GNU Compiler Collection) is a collection of compilers and libraries for the programs written in C, C++, Ada, GO, D, Fortran, and Objective-C programming languages and it is distributed under the GNU General Public License. We are going to install the GCC compiler using the Linux concluding to install C on Linux.
The GCC Compiler, and several other libraries and utilities required for edifice applications, tin exist found in the default Ubuntu repositories (Ubuntu is a Linux-based Operating System) under the build-essential meta-package.
What is the build-essential Package?
This build-essential meta-package on Ubuntu comes with five dissever packages that are required during a software compilation procedure, and it contains the GCC compiler that will be used to build and run your C Programs. These five packages are listed below:
- gcc : The GNU Compiler Collection (GCC Compiler) is used to compile programs written in C Language.
- thou++ : The GNU C++ compiler is used to compile programs written in C++ Language.
- libc6-dev : This is the GNU library files parcel. The development libraries and header files needed to compile simple C and C++ programs are included in this package.
- make : This is a handy tool for decision-making the compilation of programme. This tool reads a file called a "makefile", which tells the compiler how to practice its job.
- dpkg-dev : This package can exist used to unzip, compile, and upload Debian source packages. If you wish to packet your programme for a Debian-based system, this tool will come in handy.
So, we have to perform the following steps to install the build-essential package in our Linux operating organization:
First, nosotros have to open upward the terminal; we can utilize the shortcut Ctrl + Alt + T or we can manually open it up past searching it in the bill of fare ( ⋮⋮⋮ icon).
1. To begin, update the packages list using the below command:
The apt command in Linux is in charge of installing, uninstalling, and updating applications on our system. Consider your computer to exist a factory, and the apt command to exist the factory manager who manages the installation of new equipments, removing obsolete equipments, and updating the desired equipments to the latest versions while keeping track of the equipment names and versions currently in use. So, sudo apt update command is used to update the rails of the software versions that helps in installing the newest available software version in your systems.
Notation:
sudo (Super User Practise) enables a permitted user to run a command as the superuser or some other user, depending on the security policy. And then, if required, enter your system password to proceed.
OUTPUT:
scaler@scaler-topics:~$ sudo apt update [sudo] countersign for scaler: Hitting: 1 http: //in.archive.ubuntu.com/ubuntu focal InRelease Get: 2 http: //in.archive.ubuntu.com/ubuntu focal updates InRelease [114 kB] Get: 3 http: //tn.annal.ubuntu.com/ubuntu focal backports InRelease [108 kB] Get: four http: //security.ubuntu.com/ubuntu focal-securtty InRelease [114 kB] Get: v http: //in.annal.ubuntu.com/ubuntu focal updates/main amd64 Packages [1, 468 kB] Go: 6 http: //in.archive.ubuntu.com/ubuntu focal-updates/matn 1386 Packages [585 kB] Become: seven http: //in.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [291 kB] Get: 8 http: //in.archive.ubuntu.com/ubuntu focal updates/main amd64 DEP-xi Metadata [279 kB] Become: 9 http: //in.archive.ubuntu.com/ubuntu focal-updates/master DEP-eleven 48x48 Icons [sixty.8 kB] Go: 10 http: //in.archive.ubuntu.com/ubuntu focal-updates/main DEP-11 64x64 Icon s [98.3 kB] Become: 11 http: //tn.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metad ata [14.7 kB] Get: 12 http: //in.annal.ubuntu.com/ubuntu focal-updates/restricted amd64 Packa ges [694 kB] Go: thirteen http: //tn.annal.ubuntu.com/ubuntu focal-updates/restricted Translation -en [99.0 kB] Get: xiv http: //tn.annal.ubuntu.com/ubuntu focal-updates/untverse 1386 Packages [663 kB] Get: fifteen http: //in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 Parcel s [892 kB] Get: 16 http: //tn.archive.ubuntu.com/ubuntu focal-updates/universe Translation-e due north [196 kB] ...
ii. Install the package build-essential using the following command:
$ sudo apt install build-essential
If required enter your system password to go on.
OUTPUT:
scaler@scaler-topics:~$ sudo apt install build-essential [sudo] password for scaler: Reading package lists... Done Building dependency tree Reading state information... Washed The following boosted packages will exist installed: binutils binutils-common binutils-x86 -64 -linux-gnu dpkg-dev fakeroot thousand++ g++ -9 gcc gcc -nine libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcrypt-dev libctf-nobfd0 libctf0 libfakeroot libgcc -nine -dev libitm1 liblsan0 libquadmath0 libstdc++ -9 -dev libtsan0 libubsan1 linux-libc-dev make manpages-dev Suggested packages: binutils-medico debian-keyring one thousand++-multilib g++ -9 -multilib gcc -9 -doc gcc-multilib autoconf automake libtool flex bison gcc-doctor gcc -ix -multilib gcc -9 -locales glibc-doctor libstdc++ -9 -doc make-doc The post-obit NEW packages will be installed: binutils binutils-mutual binutils-x86 -64 -linux-gnu build-essential dpkg-dev fakeroot g++ g++ -nine gcc gcc -ix libalgorithm-unequal-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcrypt-dev libctf-nobfd0 libctf0 libfakeroot libgcc -9 -dev libitm1 liblsan0 libquadmath0 libstdc++ -9 -dev libtsan0 libubsan1 linux-libc-dev make manpages-dev 0 upgraded, 32 newly installed, 0 to remove and 259 not upgraded. Need to get 3518 kB/ 34.4 MB of athenaeum. After this operation, 157 MB of additional deejay infinite will exist used. Do y'all desire to continue ? [Y/n]
Printing the Y key and so Enter key one time you get the like output equally higher up on your screen to go on the installation process.
It volition take three-five minutes to install the build-essential meta-package completely. This procedure will install C on Linux operating system and we can use the GCC compiler to compile and run our C Programs.
Congratulations! Now you accept completed the installation of the build-essential package and the GCC Compiler (C Lanuguage) in Linux.
Annotation:
Nosotros are using Ubuntu 20.04 LTS version in this tutorial. This version of Ubuntu comes with a pre-installed version of the GCC compiler, so you can first check the installed compiler version using the control mentioned in the adjacent section.
For Crimson Chapeau Linux / Fedora / CentOS
There is no build-essentials package in Carmine Hat Linux, Fedora or CentOS but we can install C on Linux through a similar package in these operating systems required for software evolution. And so, if y'all are using a Red Hat Linux / Fedora / CentOS based Linux operating system, then yous have to install the Development Tools package to get the GCC compiler in your organization.
i. First update the packages list using the below command as root user:
2. Install Evolution Tools using the beneath command as root user:
# yum groupinstall 'Development Tools'
or
$ sudo yum group install "Development Tools"
Check the Installed Compiler Version
At present that you accept installed the build-essentials / Development Tools package, you can easily check/validate your GCC Compiler version. In this section, yous will meet how you tin can check/validate the installed GCC compiler version by using the below command in your Linux terminal:
Note:
--version flag under the gcc control is compatible with nigh all the final development software in Linux.
OUTPUT:
scaler@scaler-topics:~$ gcc -- version gcc (Ubuntu nine.3 .0 -17u buntu1~ 20.04 ) nine.three.0 Copyright (C) 2022 Costless Software Foundation, Inc. This is free software ; see the source for copying conditions. At that place is NO warranty; non even for MERCHANTABILITY or Fitness FOR A PARTICULAR PURPOSE.
If y'all see an output like the above-displayed output on your screen, you lot are adept to get.
Note:
If the output looks like the below output, in that location was some discrepancy during the installation process. Repeat the steps mentioned above to install build-essential package again.
scaler@scaler-topics:~$ gcc --version Command 'gcc' not found, but can be installed with: sudo apt install gcc
Creating a C Program
In this department, you will to create a simple C program on Linux using a pre-installed text editor.
At that place are many Linux terminal commands to create a new file like using the bear on, > (redirect operator), cat, repeat commands, or terminal editors like vi, vim, or nano. We are using the bear on control in this tutorial in the concluding to create an empty C program file. Before creating a new file, you can too change the directory of the concluding to whatever desired location in your system. Nosotros have chosen the Desktop directory in this tutorial. You lot can modify to Desktop directory using cd Desktop (change directory to Desktop ) control or you tin can choose any directory of your choice, just pass the location address of the directory afterward the cd control. Yous have to make sure that the C program file is compiled in the aforementioned directory as where the C program file is present.
Permit'southward see this in action in Ubuntu 20.04 Bone.
Step 1: bear on hello.c command in the final will create an empty howdy.c C programme file in the desktop directory.
Step two: Open the hullo.c file in the in-built text editor of Linux (or y'all can use any editor of your choices like Sublime Text or Visual Studio Code) and blazon the Hullo World C program in the editor equally given beneath.
Howdy World Program in C
// C Program to print Hi, Globe! in the output # include <stdio.h> int main () { // printf function is used to print the string argument in the output window printf ( "How-do-you-do, Earth!\n" ); render 0 ; }
You tin also bank check and run this programme hither. (IDE by InterviewBit)
OUTPUT:
Hello, World!
Congratulations! You're at present but i step away from compiling a C program nether the Linux operating organisation. So far, You have created a new file how-do-you-do.c through the terminal and successfully written the Hello World programme in the in-built text editor.
Now let u.s.a. encounter how to compile the above C plan file in the Linux terminal.
Compiling and Executing the C Program with GCC Compiler
To compile our C Program file, we can use the below command in the terminal (utilize this control in the same directory where the hello.c file is present):
The above command volition generate an executable file with the proper noun hi every bit given in the command after -o . We tin give any name to the executable file. Information technology is non necessary that we give the same name as the C programme file.
Note:
Nosotros also have to ensure that the above control is used in the same directory where the hello.c file is present.
Now to run this executable file, we just need to run the below command and the output of the C program will be shown on the terminal screen.
This command volition give Hello, World! output on the concluding, if you have written the same C program as mentioned in the above section.
Note :
Use this command in the same directory where the hello executable file is present.
Allow'due south come across this in activeness in Ubuntu 20.04 Os.
Step ane: Utilize gcc howdy.c -o hello control to compile the hello.c programme and generate a howdy executable file. We tin can encounter from the image that a hello file is created in the Desktop directory.
Step 2: To run the executable file just enter the ./hello command and output volition be visible on the terminal screen as shown in the beneath image.
Note:
Use this command in the aforementioned directory where the how-do-you-do executable file is present. For example, we are compiling and executing our program file on the Desktop directory.
This control will requite How-do-you-do, Globe! output on the final, if yous take written the aforementioned C plan as mentioned in the above section.
Congratulations!: You take successfully completed the compilation and running process of a C Plan nether a Linux Operating System.
Conclusion
- We learned how to install C on Linux.
- We need to install the build-essential / Evolution Tools package to install C on Linux and become the GCC Compiler in the system.
- build-essential meta-parcel comes with five separate packages that are required during a software compilation process i.e. gcc , g++ , libc6-dev , make and dpkg-dev .
- GCC compiler is used to compile and run a C program on the Linux operating system.
- Nosotros tin employ the in-build text editor or other editors like Visual Studio Code or Sublime Text to write our C Programs.
Source: https://www.scaler.com/topics/c/install-c-on-linux/
Posted by: rodriguezpight1985.blogspot.com

0 Response to "How To Install C Compiler In Ubuntu"
Post a Comment