How to Install GCC on Ubuntu 24.04, 22.04, or 20.04 - LinuxCapable (2024)

The GNU Compiler Collection (GCC) is a cornerstone in software development, equipping programmers with a robust suite of tools to compile various programming languages. Its significance spans various aspects of development, from enabling the creation of high-performance applications to supporting a multitude of programming paradigms.

Below are key highlights that underscore the utility and versatility of GCC:

  • Comprehensive Language Support: In addition to C and C++, GCC extends its capabilities to include Objective-C, Fortran, Ada, Go, and more, facilitating a diverse development ecosystem.
  • Advanced Optimization Techniques: GCC implements cutting-edge optimization strategies for developing efficient, high-speed applications.
  • Cross-Platform Compatibility: Its support for cross-compiling enables developers to build applications for different platforms and architectures seamlessly.
  • Robust Debugging Tools: GCC has extensive debugging features, allowing for detailed examination and troubleshooting of code.
  • Open Source Advantage: As an open-source project, GCC benefits from continuous updates and improvements by a global community of developers.
  • Extensible Architecture: Its modular design allows adding new languages and features, ensuring that GCC remains at the forefront of technology.
  • Compliance with Standards: GCC strives to adhere closely to industry standards for C, C++, and other languages, promoting code portability and compatibility.
  • Community and Documentation Support: A strong community and comprehensive documentation assist developers in navigating challenges and leveraging GCC’s full potential.

As we delve into the technical specifics of installing GCC on Ubuntu, we must appreciate the blend of traditional and cutting-edge features that make GCC an indispensable tool for developers. Now, let’s dive into the installation process.

Prerequisites for Installing GCC

To successfully install GCC on Ubuntu, ensure you meet the following requirements:

Minimum Hardware and Supported Ubuntu Versions

ComponentRequirement
Processor2 gigahertz (GHz) or faster dual-core processor (based on Ubuntu’s minimum requirements)
RAM4 GB or more (based on Ubuntu’s minimum requirements)
Disk Space500 MB of free space
Supported VersionsUbuntu 24.04 (Noble), Ubuntu 22.04 (Jammy), Ubuntu 20.04 (Focal)

Network and Terminal Requirements

RequirementDescription
Internet ConnectionRequired to download GCC and updates.
Terminal ConventionsAll terminal commands should be run as a regular user with sudo privileges.
CLI CommandsUse the Command Line Interface (CLI) for installation and setup.

Install GCC via Default Repository or Ubuntu ToolChain PPA

Update Ubuntu before GCC Installation on Ubuntu

Before you begin, update yoursystem to ensure all existing packages are up to date to avoid any conflicts during the installation.

sudo apt updatesudo apt upgrade

Select GCC Installation Method

Method 1: Install GCC with the Ubuntu Repository

The first recommended option to install GCC is to install either the GCC package directly or the build-essential package containing GCC and many other essential development tools such as make, g++, and dpkg-dev.

To begin the installation, use the following command.

sudo apt install gcc

Or

sudo apt install build-essential

Once installed, verify the installation and check the version using the following command.

gcc --version

Method 2: Install GCC via Toolchain PPA

The following method will install the latest GCC Compiler or alternative versions you may seek from the Ubuntu Toolchain PPA.

To import this PPA, run the following command:

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

After importing the PPA, update your Ubuntu sources list to reflect the changes made by running the following command in your terminal:

sudo apt update

To install a specific version of the GCC compiler on your Ubuntu system using the Ubuntu ToolChain PPA, use the following commands in your terminal:

  • GCC Compiler 14
sudo apt install g++-14 gcc-14
  • GCC Compiler 13
sudo apt install g++-13 gcc-13
  • GCC Compiler 12
sudo apt install g++-12 gcc-12
  • GCC Compiler 11
sudo apt install g++-11 gcc-11
  • GCC Compiler 10
sudo apt install g++-10 gcc-10
  • GCC Compiler 9
sudo apt install g++-9 gcc-9

After running the appropriate command for the version you want to install, the GCC compiler will be successfully installed on your Ubuntu system.

Note: The latest GCC release is typically released on the latest LTS releases; older releases such as 20.04 and 18.04 may not be compatible with GCC 14; for example, check the PPA to ensure compatibility.

Configure Alternative Versions of GCC

You may need to install multiple GCC compiler versions as a developer or specific user. Follow these steps to configure alternative versions of GCC on your Ubuntu system.

First, install the versions of GCC you need. You can install multiple versions of GCC along with G++ using the following command:

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

Note: This is an example command and should be modified to suit your requirements.

Once you have installed the necessary versions, use the update-alternatives command to configure each version’s priority. The following example command sets the priority split between GCC 9, GCC 10, GCC 11, GCC 12, GCC 13, and the latest GCC 14.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 90 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-13sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 80 --slave /usr/bin/g++ g++ /usr/bin/g++-13 --slave /usr/bin/gcov gcov /usr/bin/gcov-13sudo 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-12sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 70 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11sudo 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-10sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9

The above commands set GCC 12 as the highest priority with a value of 100. However, you can configure the priorities based on your preferences, such as if you need to work with the latest releases, GCC 13 or 14.

To confirm that GCC 12 is the default version on your system, run the following command:

gcc --version

Example output:

How to Install GCC on Ubuntu 24.04, 22.04, or 20.04 - LinuxCapable (1)

You can reconfigure the default GCC version on your system by using the update-alternatives command. First, use the following command to list the priorities you previously set:

sudo update-alternatives --config gcc

Example output:

How to Install GCC on Ubuntu 24.04, 22.04, or 20.04 - LinuxCapable (2)

This command will display a list of installed GCC versions and their priorities. You can then select the default version by entering the corresponding number.

That’s it! You have successfully configured alternative versions of GCC on your Ubuntu system.

Once installed, GCC can compile and run C and C++ programs on your Ubuntu system. With the addition of the manual pages package, you can also access comprehensive documentation on how to use GCC and its various features. Whether a novice or an experienced developer, having GCC installed on your Ubuntu system is essential for developing and running C and C++ programs.

Useful Links

Here are some valuable links related to using GCC:

  • GCC Official Website: Visit the official GCC website for information about the GNU Compiler Collection, its features, and the latest updates.
  • GCC Online Documentation: Access the comprehensive online documentation for detailed guides on using and configuring GCC.
  • GCC FAQ: Browse the frequently asked questions to find answers to common queries about GCC.
  • GCC Wiki: Explore the GCC wiki for additional information, tutorials, and community-contributed content.
  • GCC Readings: Discover a collection of readings and resources to deepen your understanding of GCC and its components.
  • Ubuntu Toolchain PPA: Access the Ubuntu Toolchain PPA to download and install the latest versions of GCC for Ubuntu.
  • Author
  • Recent Posts

Follow me

Joshua James

Joshua James is a seasoned Linux system administrator with a wealth of experience in the field. As the main author and owner of linuxcapable.com, Joshua has authored numerous tutorials and guides that help users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, Fedora, Debian, RHEL, openSUSE, and Arch Linux. Joshua is renowned for his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and commitment to sharing knowledge have established him as a respected figure in the field.

Follow me

Latest posts by Joshua James (see all)

  • How to Configure Nginx for PHP-FPM on Fedora 40 or 39 - Monday, June 3, 2024
  • How to Install Firefox on Debian 12, 11 or 10 - Tuesday, January 30, 2024
  • Upgrade to Ubuntu 24.04 Noble Numbat Desktop or Server - Friday, January 12, 2024

Share This Post:

FacebookXRedditLinkedInTumblrEmailTelegramWhatsAppPinterestHacker NewsMastodonPocketVKFlipboardCopy

You may also like:

  1. How to Install Python 3.10 on Ubuntu 22.04 or 20.04
  2. How to Install Python 3.8 on Ubuntu 22.04 or 20.04
  3. How to Install Firefox Beta and Nightly on Ubuntu 24.04, 22.04, or 20.04
  4. How to Install Python 3.9 on Ubuntu 22.04 or 20.04
  5. How to Install Nvidia Drivers on Ubuntu 24.04, 22.04, or 20.04
  6. How to Install Python 3.11 on Ubuntu 22.04 or 20.04
  7. How to Install Python 3.12 on Ubuntu 24.04, 22.04 or 20.04
  8. How to Install Python 3.7 on Ubuntu 22.04 or 20.04
  9. How to Enable or Disable AppArmor on Ubuntu 24.04, 22.04, or 20.04
  10. How to Install Git on Ubuntu 24.04, 22.04, or 20.04
How to Install GCC on Ubuntu 24.04, 22.04, or 20.04 - LinuxCapable (2024)
Top Articles
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 6054

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.