How to Install GCC Compiler on Ubuntu 20.04

The GNU Compiler Collection, or GCC is a compiler that is used to convert the files written in various programming languages into the executable files. It’s nothing but a rich compiler that comes with the C, C++, Go, D and many other languages. With the rich library of the components, it supports a lot of languages to make the executable binary programs. Compiling has always been hard, but with the GCC Compiler on Ubuntu 20.04, it has become easier for the users.

Many of the top programmers use GCC on Ubuntu as the primary compiler for their programming needs. Not just that, almost all of the Free and Open Source or FOSS software is compiled with the help of GNU Compiler Collection. GCC is supported by majority of the languages and also the code editors. You can use it with the VSCode or Atom code editor on Ubuntu. If you are interested to use GCC Compiler, then you must install it first on your system. In this post, we are going to share the detailed instructions on how to install GCC Compiler on Ubuntu 20.04. The installation instructions works for all of the Debian based operating systems with ease. You can follow the same methods on the Linux Ubuntu, Linux Mint, Ubuntu Mate, Debian Linux and also on Elementary OS without any issues.


Installing GCC on Ubuntu Linux

Ubuntu already comes with the default repository that contains all the compiler files. You can find the GCC Compiler in the default repository. So, installing GCC on Ubuntu is a breeze and you won’t have to worry about anything. Here are the exact steps to install GCC on your Linux machine.

  1. First of all, press “Ctrl + Alt + T” to open the Terminal. Instead of this keyboard shortcut, you can open it in Ubuntu from the Activities Tab.
  2. In the Terminal, first update the repositories with Apt-get updated command. You have to execute the command with Sudo privileges.
    sudo apt-get update
  3. After updating, install the build-essentials package that contains GCC and other essential compiling tools.
    sudo apt install build-essential
  4. If you are interested, then you can easily install the Manuals about using these compilers and essential tools. This is an optional step and not compulsory at all.
    sudo apt-get install manpages-dev
  5. That’s it! GCC Compiler has been installed successfully on Linux. You can easily use it as your primary compiler for the preferred programming language. To confirm the GCC Ubuntu installation, enter the following command and execute the same.
    gcc --version
  6. This will show the details about the installed version of GCC. If you can’t see the version details, then follow the steps one to four to install it again.


How to Install Multiple Versions of GCC | Ubuntu Install GCC Linux

According to the programming principles and requirements, every developer has the version preference for GCC. With the multiple versions, it becomes easier to switch to the right GCC version to compile the appropriate code. In this section, you will learn how to install multiple versions of GCC Compiler in Ubuntu 20.04.

  1. All versions of GCC are added in the Ubuntu Toolchain PPA. First, add the Toolchain PPA in Ubuntu.
    sudo add-apt-repository ppa:ubuntu-toolchain-r/test
  2. After adding the Toolchain PPA, enter the apt-update command to update the repository list and contents.
    sudo apt-get update
  3. Enter the following command to install multiple GCC versions in your Ubuntu system. You can add or remove the appropriate versions in this command and install the same.
    sudo apt install gcc-7 g++-7 gcc-8 g++-8 gcc-9 g++-9 gcc-10 g++-10 gcc-11 g++-11
  4. Once installed, you have to set the priority for your GCC version. You have to set the priority for the GCC with the command line interface. You can change the priority anytime.
    sudo update-alternatives --config gcc
  5. Above command will open up the configuration for GCC priority Ubuntu. The output will look like the following text.
    There are 3 choices for the alternative gcc (providing /usr/bin/gcc).
    Selection Path Priority Status
    * 0 /usr/bin/gcc-10 100 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
    3 /usr/bin/gcc-10 100 manual mode
    Press <enter> to keep the current choice[*], or type selection number:
  6. To select the priority, enter the number associated with the gcc-10 Ubuntu version and press Enter. This will set the priority for the selected version in Ubuntu.


Frequently Asked Questions on GCC Compiler in Ubuntu


#1 – Does Ubuntu have GCC?

No. GCC is not installed on Ubuntu by default. It’s added in the default repository, so you can easily install it on your system.

#2 – Where is GCC Compiler Located in Ubuntu?

GCC Compiler files are stored in the “/usr/bin” directory in the system. You can find all GCC compiler files in the same directory.

#3 – How Do I Know if GCC is Installed on Linux?

If you want to know if GCC compiler is installed on Linux, then open the Terminal and enter “GCC –version” command. This will show you the output with the version number, if GCC is installed. Otherwise, the command will return with error.


Final Words

Ubuntu Install gcc-11 process is pretty simple and it won’t take more than a few minutes if you are proficient with the linux commands. With this guide, you will be able to install GCC compiler in Ubuntu 20.04 within a few minutes. Now, it’s time to use the GCC compiler to compile the executable binaries of any code with ease. Also, you should take a look at GCC Documentation for getting the idea on how to properly use it and gain knowledge.