Summer Sale 2026 – NPI EA (cat = Baeldung on Linux)
announcement - icon

Yes, we're now running our only Summer Sale. All Courses are 30% off until 20th July, 2026:

>> EXPLORE ACCESS NOW

Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

1. Overview

GCC (GNU Compiler Collection) is a free and open-source compiler system that supports several programming languages, including C, C++, and Fortran. GCC is widely used by developers around the world due to its robustness, performance, and adherence to standards.

In this tutorial, we’ll take a look at three methods that enable us to install the last iteration of GCC on Ubuntu. By doing so, we gain access to the latest features, optimizations, and bug fixes, ensuring code runs efficiently and smoothly.

2. Installation Using APT

The first method that we can follow to install GCC on Ubuntu is using the APT package manager.

Before checking out the step-by-step process, let’s note that the Ubuntu Universe repository contains GCC-14 (14.2.0, specifically), which is the latest version available.

So, we start the process by enabling the Universe repository on the machine using the add-apt-repository command, as it’s not enabled by default on Ubuntu:

$ sudo add-apt-repository universe

Then, let’s update the package list on the system:

$ sudo apt update

Next, we install GCC on the machine:

$ sudo apt install gcc-14

After the installation is complete, let’s verify it by performing a version check:

$ gcc-14 --version
gcc-14 (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0

As we can see above, the latest version is now installed on the system.

3. Installation Using PPA

Another method to install GCC on Ubuntu employs a PPA (Personal Package Archive). A PPA is a way for users to install software packages that aren’t yet available directly in the official Ubuntu repositories. This method may help us get the latest version when the Ubuntu Universe repository doesn’t contain it.

Let’s go through the steps one by one.

3.1. Installing Required Dependencies

To begin with, we update the package list on the system:

$ sudo apt update

Then, let’s install the necessary dependencies:

$ sudo apt install software-properties-common

Let’s move on to the next step.

3.2. Adding the Required GCC PPA

There are lots of GCC PPAs available on the Web. In this case, we use the ubuntu-toolchain-r/test PPA.

So, let’s leverage the add-apt-repository command to add this PPA to the system:

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test

Next, we again update the package list:

$ sudo apt update

Now, let’s go ahead to the final step.

3.3. Installing GCC

Of course, after making the necessary preparations, we should be able to install GCC on the system:

$ sudo apt install gcc-14 -y

The -y option, short for –yes, inserts yes as an answer to all the prompts during the process, helping us perform a smooth installation.

After the operation is complete, GCC should be successfully installed on the system.

Let’s verify that by doing a version check:

$ gcc --version
gcc-14 (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0

The latest version is installed on the machine.

4. Installation From Source

We can also install GCC from source on Ubuntu. Just like the previous method, this method may also help us get the latest version when that’s not present in the Ubuntu Universe repository. Let’s check out the step-by-step process for performing this type of installation.

4.1. Installing Necessary Dependencies

The primary step is to install the necessary dependencies on the system.

As usual, we first update the package list on the machine:

$ sudo apt update

Then, let’s install the required dependencies:

$ sudo apt install build-essential libmpfr-dev libgmp3-dev libmpc-dev -y

At this point, we should be ready to build GCC.

4.2. Downloading GCC

To begin with, let’s utilize the wget command to download the source code as a .tar archive from the official GCC website:

$ wget http://ftp.gnu.org/gnu/gcc/gcc-14.2.0/gcc-14.2.0.tar.gz

In the above link, we used 14.2.0 as the version to download since it’s the current latest version available for GCC.

Once the download is complete, let’s navigate to the location where the downloaded .tar archive is stored, which is /usr in this case:

$ cd /usr

After that, we use the tar command to extract the contents from the .tar archive to the current directory:

$ tar -xf gcc-14.2.0.tar.gz

Here, the -x option, short for –extract, extracts the contents from the archive and the -f option, short for –file, specifies the archive that contains the files to extract.

After extraction, a new subdirectory with the contents from the .tar archive appears in the working directory.

4.3. Preparing for Installation

Let’s navigate to the new subdirectory:

$ cd gcc-14.2.0

Then, we use the ./configure command to get the system ready for the installation:

$ ./configure -v --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --prefix=/usr/local/gcc-14.2.0 --enable-checking=release \
--enable-languages=c,c++ --disable-multilib --program-suffix=-14.2.0

Command completed successfully.

The last line suggests that the machine is ready for the installation.

4.4. Installing GCC

The final step is to build and install GCC on the system.

So, let’s build it by running the make command:

$ make

Finally, we install GCC on the machine:

$ sudo make install

After completion, we should have the utility successfully installed on the system.

Let’s perform a version check to verify the installation:

$ /usr/local/gcc-14.2.0/bin/gcc-14.2.0 --version
gcc-14.2.0 (GCC) 14.2.0

Visibly, the latest version is now installed on the machine.

5. Conclusion

In this article, we’ve provided a detailed explanation of three methods that we can use to install GCC on Ubuntu.

By following any of these methods, we can seamlessly integrate GCC with a Ubuntu system and start compiling code.