This brief tutorial shows students and new users how to install GCC Compiler (build-essential) on Ubuntu Linux.
The GNU Compiler Collection (GCC) is a collection of compilers and libraries developed by the GNU Project that supports programming languages such as C, C++, Objective-C, Fortran, Go, and many more.
GCC is a core part of the Linux operating system and many open-source projects and tools. Linux kernel is also compiled with GCC, so it’s a big deal in the open-source community.
If you’re a new user or student looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.
Ubuntu is an open-source Linux operating system that runs on desktops, laptops, servers, and other devices.
For more about GCC, please visit its project page.
To get started with installing the GCC compiler on Ubuntu, follow the steps below:
How to install GCC on Ubuntu Linux
Out of the box, Ubuntu repositories contain a build-essential package that contains the GCC compiler, g++, make and a lot of libraries and other utilities required for compiling other packages and tools.
So installing the GCC compiler on Ubuntu is as simple as installing the build-essential package.
To do that, run the commands below:
sudo apt update sudo apt install build-essential
The commands install many other packages, GCC, g++, and make.
If you’re a developer and want to install the manual page for GCC, simply run the commands below:
sudo apt-get install manpages-dev
After installing, to verify that GCC is successfully installed and functioning, simply use the GCC --version command as shown below:
That should print out the output as shown below:
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
This is how to install the GCC compiler on Ubuntu if you don’t already have it installed.
How to install multiple versions of GCC
Those who want to install multiple versions of the GCC compiler can use option #2.
New versions of the GCC compilers support new languages, better performance, and extended features. If you want to take advantage of these additional features, then installing the latest or multiple should be ideal.
To install the latest versions of the GCC compilers, you will have to add a third-party PPA repository to Ubuntu and install it from there.
To do that, simply run the commands below:
sudo apt install software-properties-common sudo add-apt-repository ppa:ubuntu-toolchain-r/test
After adding the repository above, you can then install multiple GGC versions using their version number.
sudo apt update sudo apt install gcc-7 g++-7 gcc-8 g++-8 gcc-9 g++-9
Because you have multiple versions of the GCC compiler installed, there’s a priority number that gets associated with each. The version with the highest priority will be the default system compiler.
You will have to run the commands below to set the default system compiler associating each with a priority number.
In the case below, gcc-9 is the version with the highest priority [ 90 ].
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7
Later if you want to change the default version use the update-alternatives command below:
sudo update-alternatives --config gcc
There should be multiple choices depending on the number of compilers installed.
Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/gcc-9 90 auto mode 1 /usr/bin/gcc-7 70 manual mode 2 /usr/bin/gcc-8 80 manual mode 3 /usr/bin/gcc-9 90 manual mode Press to keep the current choice[*], or type selection number:
Select your choice and press Enter.
That should update the system with the current default.
You have learned how to install the GCC compiler on Ubuntu 18.04 | 16.04. If you find any error above, please use the comment form below to report it.
I’m not able to install the g++ 4.8, only the gcc versions seems to be covered in this ppa?