How to Install GCC on Linux Mint 21 or 20

The GNU Compiler Collection, commonly known as GCC, is an essential toolkit for software developers. It supports a multitude of programming languages and plays a crucial role in the development of open-source software. If you plan to install GCC on Linux Mint 21 or Linux Mint 20, this guide is specifically crafted for you.

Key Features of GCC:

  • Multi-Platform Support: GCC is compatible with various operating systems, including Linux, Windows, and macOS, offering flexibility for developers who work on multiple platforms.
  • Broad Language Support: Whether you’re working with C, C++, Objective-C, or Fortran, GCC can compile a wide range of programming languages.
  • Optimization Features: GCC provides different levels of code optimization, enabling developers to produce efficient and resource-saving applications.
  • Language Extensions: Besides adhering to standard language specifications, GCC offers language extensions that provide developers with more coding flexibility.
  • Strong Community Support: The community behind GCC ensures the tool is continually updated and aligned with emerging language standards.

GCC is a favored compiler for many Linux distributions, including Linux Mint. It assists developers in compiling, fine-tuning, and debugging software applications. Its adaptability and comprehensive language support make it a valuable asset in any developer’s toolkit.

In the forthcoming guide, we’ll explore two installation avenues for GCC on Linux Mint 21 or Linux Mint 20. The first method involves using Linux Mint’s default repository, while the second taps into the Ubuntu Toolchain Launchpad PPA, which offers the latest GCC versions, including GCC 13, 12, 11, 10, and 9. Stay tuned for detailed steps to equip your Linux Mint system with this versatile compiler.

Section 1: Installing GCC Using Linux Mint Default Repository

This section outlines the steps for installing GCC using the default repository provided by Linux Mint. Utilizing the default repository is recommended, as it ensures compatibility with your system’s packages.

Step 1: Update Linux Mint Packages

Updating your system is a crucial preliminary step. This ensures that all existing packages are up-to-date, minimizing the likelihood of package conflicts during the installation of GCC.

sudo apt update && sudo apt upgrade

Step 2: Install GCC from the Linux Mint Repository

After updating the system, the next step is to install GCC. There are two options available:

  1. Install just the GCC package.
  2. Install the build-essential package which encompasses GCC along with an assortment of development tools such as make, g++, and dpkg-dev.

The build-essential package is handy if you plan to do development in C or C++, as it includes additional libraries and tools that are often required.

To install GCC alone on Linux Mint:

sudo apt install gcc

Alternatively, to install the build-essential package:

sudo apt install build-essential

Step 3: Verify GCC Installation on Linux Mint

After installation, it is prudent to verify that GCC has been successfully installed and is accessible from the command line. Moreover, checking the version of GCC will provide insights into the features and capabilities available to you, as different versions of GCC support different language standards and optimizations.

To verify the installation and check the version of GCC:

gcc --version

This command will output the version of GCC installed, confirming that the installation process was successful.

Section 2: Install GCC Using Ubuntu Toolchain PPA on Linux Mint

This section elucidates the steps for installing the latest or alternative versions of GCC Compiler using Ubuntu Toolchain PPA on Linux Mint. This method is suitable if you are looking for a specific version of GCC that is not available in the default Linux Mint repository.

Step 1: Import Ubuntu Toolchain PPA on Linux Mint

To begin, we will import the Ubuntu Toolchain PPA, which hosts a variety of GCC versions. This is done via the add-apt-repository command. The -y flag is used to accept the prompt that would otherwise be displayed automatically.

sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y

Step 2: Update Package List for Ubuntu Toolchain PPA on Linux Mint

After adding the PPA, it is necessary to update the package list so that apt is aware of the new packages available from the Ubuntu Toolchain PPA. This ensures the latest metadata is fetched for the packages you will install.

sudo apt update

Step 3: Install the Desired GCC Version on Linux Mint

You can install the GCC version that meets your requirements at this juncture. The Ubuntu Toolchain PPA provides several versions of GCC. For example, GCC 13, 12, 11, 10, and 9 were available when this guide was written.

Here are the commands to install these versions:

sudo apt install g++-13 gcc-13
sudo apt install g++-12 gcc-12
sudo apt install g++-11 gcc-11
sudo apt install g++-10 gcc-10
sudo apt install g++-9 gcc-9

These commands will install the GCC and G++ compilers for your chosen version.

Step 4: Validate the Installation of GCC on Linux Mint

After the installation, validating that the GCC compiler was installed successfully is wise. Use the following command to confirm that the chosen version of GCC is available for use:

gcc-12 --version # Replace 12 with the version you installed

Section 3: Setting Up Multiple GCC Compiler Versions on Linux Mint

In specific scenarios, as a developer or system administrator, you may need multiple versions of GCC installed on your Linux Mint system. This section will guide you through installing multiple versions of GCC and configuring the system to switch between them as needed.

Step 1: Install Multiple GCC Versions on Linux Mint via Toolchain PPA

First, let’s focus on installing the GCC versions you need. This command will install several versions of GCC along with their corresponding G++ (the C++ compiler) versions:

sudo apt install gcc-9 g++-9 gcc-10 g++-10 gcc-11 g++-11 g++-12 gcc-12 g++-13 gcc-13

This command installs GCC versions 9, 10, 11, 12, and 13 and their corresponding G++ versions.

Step 2: Configure GCC Version Priorities

Now that multiple versions are installed, it’s essential to let the system know how to choose between them. This is where the update-alternatives command comes into play.

The update-alternatives command allows you to set priorities for each version of GCC. In the example below, we’re setting GCC 12 as the highest priority, followed by GCC 11, GCC 10, and GCC 9.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 90 --slave /usr/bin/g++ g++ /usr/bin/g++-13 --slave /usr/bin/gcov gcov /usr/bin/gcov-13
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 80 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 40 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9

These commands associate each GCC version with a priority level (100 for GCC 12, 90 for GCC 13, 80 for GCC 11, and so on). The system will default to the version with the highest priority, but you can change this later if needed, as in the case above, where I wanted to work with GCC 12.

Step 3: Verify Default GCC Version on Linux Mint

After configuring the priorities, let’s confirm that the expected version is now the default GCC version. Use the following command:

gcc --version

Step 4: Switch Between GCC Versions on Linux Mint

If you need to switch to a different GCC version, you can easily reconfigure the default version using the update-alternatives command. The following command will display the installed versions along with their priorities:

sudo update-alternatives --config gcc
Screenshot showing how to switch from GCC 12 to GCC 11 on Linux Mint using the update-alternatives commandPin
Example screenshot demonstrating switching from GCC 12 to GCC 11 on Linux Mint using the update-alternatives command.

This will present you with a list of the installed GCC versions. Simply enter the number corresponding to the version you want to make the default and press Enter.

Section 4: Create a Test Application with GCC on Linux Mint (Optional)

In this section, you will learn how to verify that the GCC compiler functions properly by creating a simple C program. This is essential to ensure the installed GCC compiler is ready for your development projects.

Step 1: Create a C Program

To begin, let’s create a basic C program. We will be utilizing nano, which is a straightforward text editor in the terminal.

Open Nano and Create a New File

Enter the following command to open nano and create a new file called hello.c:

nano hello.c

Insert Code into the File

Once the text editor is open, add the following code to hello.c:

#include <stdio.h>

int main()
   printf("Hello, World from!");
   return 0;

This code is a simple C program that prints a message to the console.

Save and Exit the File

To save the file, press CTRL+O. This will write the changes to the file. To exit nano, press CTRL+X.

Step 2: Compile the C Program

Now that the source code is ready compiling the program is time. Compiling transforms the source code into an executable file for the system.

Use the gcc command to compile the program:

gcc hello.c -o hello

Here, gcc is the command to run the GCC compiler, hello.c is the name of the file you want to compile, and -o hello specifies the name of the output file, in this case, hello.

Step 3: Execute the Compiled Program

Finally, let’s execute the compiled program. This is done by entering the following command:


Upon execution, you should observe the following output in your terminal:

Hello, World from!

This output confirms that your GCC compiler is correctly installed and functioning as expected. It’s now ready for you to start developing and compiling your C and C++ applications on Linux Mint.


This guide meticulously explored installing the GCC on Linux Mint 21 or 20. This involved setting up repositories, installing the necessary packages, and confirming the installation. Moreover, we delved into configuring alternative versions of GCC and testing its functionality through a simple C program. It’s imperative to recognize that the GCC compiler is a linchpin for developers, especially those working in C and C++.

My final recommendation is to keep your GCC compiler updated and regularly verify that it’s configured correctly to meet your development needs. Staying current with updates ensures compatibility, performance optimization, and security.

Share to...