What is GCC?
The GNU Compiler Collection, commonly known as GCC, is a set of compilers
and development tools available for Linux, Windows, various BSDs and other
operating systems. It includes support primarily for C and C++ and includes
Objective-C, Ada, Go, Fortran. The Free Software Foundation (FSF) wrote GCC
and released it as completely free (as in libre) software. GCC is a toolchain
that compiles code, links it with any library dependencies, converts that code
to assembly, and then prepares executable files. When you run GCC on a
source code file, it first uses a preprocessor to include header files and
discard comments.
Perform the steps below to install the GCC Compiler Ubuntu :
1. Start by updating the packages list:
sudo apt update
2. Install the build-essential package by typing:
sudo apt install build-essential
The command installs a bunch of new packages including gcc, g++
3. To validate that the GCC compiler is successfully installed, use the gcc
--version command which prints the GCC version:
gcc --version
The default version of GCC available in the Ubuntu repositories is 5.4.0:
gcc (Ubuntu 5.4.0-1ubuntu1~18.04)5.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software. GCC is now installed on your system, and you can
start using it.
Compiling a Hello World Example
Open your text editor and create the following file:
nano hello.c
This will create a binary file named hello in the same directory where you run
the command.
Execute the hello program with:
./hello