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.
Installing GCC on Ubuntu Linux is necessary for developers who want to compile and build applications written in programming languages such as C, C++, Objective-C, Fortran, Go, and many more.
GCC is a core part of the Linux operating system, and it includes many open-source projects and tools. The Linux kernel is compiled with GCC. If you’re a new user or student looking to learn programming on Linux, Ubuntu is a great Linux operating system for beginners and the most accessible place to start.
The build-essential package containing the GCC compiler, g++, make, and many libraries and other utilities required for compiling other packages and tools is already available in Ubuntu repositories, making it easy to install GCC on Ubuntu Linux.
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 containing the GCC compiler, g++, make, and many 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:
gcc --version
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 GCC compiler versions can use option #2.
New versions of the GCC compilers support new languages, better performance, and extended features. Installing the latest or multiple should be ideal to take advantage of these additional features.
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 install multiple GGC versions using their version number.
Example:
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, a priority number gets associated with each. The version with the highest priority will be the default system compiler.
You must run the commands below to set the default system compiler to associate 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.
Conclusion
- Installing the GCC compiler on Ubuntu is straightforward through the
build-essential
package. - Having GCC allows developers to compile applications written in C, C++, and Fortran.
- Users can install multiple versions of GCC to take advantage of new language features and improvements.
- The priority system for GCC versions enables easy management and switching between compiler versions.
- Regular updates to GCC ensure that users have access to the latest performance enhancements and language support.
Leave a Reply to hans Cancel reply