The GNU Compiler Collection (GCC) is the open-source compiler toolchain that builds Linux kernel modules, system utilities, scientific simulations, and software demanding standards compliance and performance tuning. Whether you are compiling custom drivers for hardware, building high-performance computing applications, developing embedded systems firmware, or contributing to open-source projects that require specific compiler versions, GCC delivers the optimization techniques and cross-platform support that makes it essential for C and C++ development on Linux.
This guide covers installing GCC on Linux Mint through the default repository for stable builds, using the Ubuntu Toolchain PPA for additional versions, configuring multiple GCC versions with update-alternatives, compiling from source for the latest upstream releases, and switching between compiler versions for different project requirements. By the end, you will have a fully functional GCC development environment with the flexibility to target specific compiler versions as your projects demand.
Choose Your GCC Installation Method
Linux Mint provides multiple paths for installing GCC, each serving different development scenarios. Understanding these options helps you balance stability, version recency, and maintenance effort based on your project requirements.
This guide supports Linux Mint 22.x (based on Ubuntu 24.04) and Linux Mint 21.x (based on Ubuntu 22.04). GCC version availability differs between releases: Mint 22 provides GCC 9 through 14 from the default repositories, while Mint 21 provides GCC 9 through 12. Commands work identically across supported releases unless noted otherwise.
| Method | GCC Versions | Best For | Trade-offs |
|---|---|---|---|
| Default Repository | Mint 22: GCC 9-14; Mint 21: GCC 9-12 | General development, production builds, systems requiring stability | Mint 21 users cannot access GCC 13/14 through packages |
| Ubuntu Toolchain PPA | Test builds and patches for existing versions | Developers wanting the latest patches before they reach default repos | Does not add newer major versions beyond what repos already provide |
| Compile from Source | Any release from the GNU FTP server | Mint 21 users needing GCC 13/14, bleeding-edge features, custom configurations | Time-consuming build process, manual updates, no automated security patches |
For most users, the default repository method is recommended because it provides compiler versions thoroughly tested against your system libraries, ensuring maximum compatibility and minimizing unexpected build failures. Mint 21 users who specifically require GCC 13 or 14 should use the source compilation method since these versions are not available through packages for Ubuntu 22.04-based systems.
Update Linux Mint Before Installation
Before installing GCC, update your system packages to ensure all existing packages are current and avoid version conflicts during installation. Running these commands refreshes your package index and installs any pending updates:
sudo apt update && sudo apt upgrade
The apt update command refreshes the package index, while apt upgrade installs any pending updates. This ensures your system has the latest security patches and package versions before adding development tools.
Method 1: Install GCC from the Default Repository
The default repository provides the most straightforward GCC installation path for general development. This method installs compiler versions officially supported by your Linux Mint release, thoroughly tested against system libraries for maximum compatibility.
Install build-essential for Complete Development Tools
Open a terminal and install build-essential, a metapackage that bundles GCC, G++ (the C++ compiler), Make, dpkg-dev, and other essential compilation tools. A metapackage is a convenient bundle that installs multiple related tools at once. While you can install standalone gcc, build-essential prevents you from discovering missing dependencies when attempting to compile software later:
sudo apt install build-essential
The installation downloads approximately 50-80 MB of packages and typically completes within a few minutes depending on your internet connection speed. Once finished, verify the installation and confirm the compiler version:
gcc --version
Expected output on Linux Mint 22:
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 Copyright (C) 2023 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.
Expected output on Linux Mint 21:
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Copyright (C) 2021 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.
The version string shows the GCC version with Ubuntu’s package identifier, indicating this is Ubuntu’s packaged version specifically built for your release. Your exact version number may differ slightly based on recent security updates.
Install Specific GCC Versions
If you need a specific GCC version for compatibility with a particular project, install it alongside the default version. The available versions depend on your Linux Mint release:
Linux Mint 22 (Ubuntu 24.04 base):
sudo apt install gcc-14 g++-14
sudo apt install gcc-13 g++-13
sudo apt install gcc-12 g++-12
sudo apt install gcc-11 g++-11
Linux Mint 21 (Ubuntu 22.04 base):
sudo apt install gcc-12 g++-12
sudo apt install gcc-11 g++-11
sudo apt install gcc-10 g++-10
sudo apt install gcc-9 g++-9
GCC 13 and 14 are not available for Linux Mint 21 through the default repositories or the Ubuntu Toolchain PPA. If you need these versions on Mint 21, use the source compilation method (Method 3) or upgrade to Linux Mint 22.
After installing a specific version, verify it by appending the version number to the command:
gcc-12 --version
Expected output:
gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04.2) 12.3.0 Copyright (C) 2022 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.
Method 2: Add the Ubuntu Toolchain PPA
The Ubuntu Toolchain PPA (Personal Package Archive) provides test builds and patches for GCC versions before they reach the default repositories. This method is useful when you need the very latest bug fixes or patches for an existing GCC version, though it does not add major new versions beyond what your repositories already provide.
Import the Ubuntu Toolchain PPA
First, add the Ubuntu Toolchain PPA to your system. The -y flag automatically confirms the PPA addition without prompting:
sudo add-apt-repository ppa:ubuntu-toolchain-r/ppa -y
This command imports the PPA’s GPG signing key and adds the repository configuration. Next, update the package index to refresh the repository metadata with the newly added PPA packages:
sudo apt update
After updating, you can install any GCC versions available for your release using the same commands shown in Method 1. The PPA primarily provides updated patch versions (for example, GCC 12.3.1 instead of 12.3.0) rather than entirely new major versions.
Method 3: Compile GCC from Source
Compiling GCC from source provides access to the absolute latest upstream releases directly from the GNU project before they reach Ubuntu’s repositories. This method delivers complete control over compilation options, language support, and optimization flags, making it the only option for Linux Mint 21 users who need GCC 13 or 14.
Source builds typically consume 30-60 minutes on modern multi-core systems and require 4-6 GB of temporary disk space during compilation. Reserve this method for scenarios where packaged versions lack required features or when you need precise control over the compiler toolchain configuration.
Install Build Dependencies
Before compiling GCC, install the prerequisite development tools and mathematical libraries GCC requires for its build system:
sudo apt install build-essential flex bison libgmp3-dev libmpc-dev libmpfr-dev libisl-dev texinfo wget curl
These packages provide essential compilation tools: build-essential supplies the base compiler toolchain, flex and bison handle lexical analysis and parsing, the -dev packages provide mathematical precision libraries (GMP, MPC, MPFR) and optimization frameworks (ISL), while texinfo generates documentation. Without these dependencies, the GCC build process will fail with errors about missing headers or libraries.
Download and Extract GCC Source Code
The following script automatically detects and downloads the latest GCC release for your chosen major version series. Set the GCC_MAJOR variable to your desired version (14, 13, 12, etc.), and the script fetches the newest patch release from the GNU FTP server:
#!/bin/bash
# Set your desired GCC major version (change this for different versions)
GCC_MAJOR=14
# Detect the latest release for this major version
GCC_VERSION=$(curl -s https://ftp.gnu.org/gnu/gcc/ | grep -oP "gcc-${GCC_MAJOR}\.\d+\.\d+" | sort -V | tail -1)
if [ -z "$GCC_VERSION" ]; then
echo "Error: Could not find GCC $GCC_MAJOR releases"
exit 1
fi
echo "Latest GCC $GCC_MAJOR release: $GCC_VERSION"
# Download and extract
cd ~
wget "https://ftp.gnu.org/gnu/gcc/${GCC_VERSION}/${GCC_VERSION}.tar.xz"
tar -xf "${GCC_VERSION}.tar.xz"
cd "$GCC_VERSION"
# Download prerequisites
./contrib/download_prerequisites
echo "GCC source ready for compilation in ~/$(pwd)"
Save this script as download-gcc.sh, make it executable with chmod +x download-gcc.sh, and run it with ./download-gcc.sh. The script queries the GNU FTP server to find the latest patch version (for example, 14.3.0 instead of 14.2.0), ensuring you always compile the newest stable release.
To compile a different major version, change
GCC_MAJOR=14to your desired version number (such asGCC_MAJOR=13orGCC_MAJOR=12). Re-run the script whenever you want to update to a newer patch release.
Expected output when the script completes:
Latest GCC 14 release: gcc-14.3.0 gmp-6.3.0.tar.bz2: OK mpfr-4.2.1.tar.bz2: OK mpc-1.3.1.tar.gz: OK isl-0.26.tar.bz2: OK All prerequisites downloaded successfully. GCC source ready for compilation in ~/gcc-14.3.0
Configure and Build GCC
GCC’s build system requires compiling in a separate directory to keep the source tree clean. Create a build directory, configure the compilation options, and compile GCC with parallel jobs:
mkdir build && cd build
Now configure the GCC build with your desired installation prefix and language support. Adjust the prefix path to match the version you downloaded (the script output shows the exact version):
# Adjust the version number to match your download (e.g., gcc-14.3, gcc-13.4, gcc-12.5)
../configure --prefix=/usr/local/gcc-14.3 --disable-multilib --enable-languages=c,c++
The --prefix option determines where GCC installs. Using /usr/local/gcc-14.3 keeps it separate from system packages and allows multiple versions to coexist. The --disable-multilib flag skips 32-bit library support on 64-bit systems, reducing build time and disk space unless you specifically need to compile 32-bit binaries. The --enable-languages=c,c++ option builds only C and C++ compilers; add fortran, go, or other languages if your projects require them.
Once configuration completes successfully, compile GCC using all available CPU cores for parallel compilation:
make -j"$(nproc)"
The -j flag enables parallel compilation jobs, while $(nproc) automatically detects your CPU core count. Expect this step to take 30-60 minutes depending on your hardware. On a modern 8-core system, the build typically completes in 25-30 minutes.
Install the compiled GCC binaries, libraries, and documentation to your configured prefix location:
sudo make install
Register the Source-Built Compiler
After installation completes, register the new compiler with update-alternatives so your shell can locate it automatically when you type gcc. Adjust the paths to match your installed version:
# Adjust paths to match your installed version (e.g., gcc-14.3, gcc-13.4)
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-14.3/bin/gcc 140 --slave /usr/bin/g++ g++ /usr/local/gcc-14.3/bin/g++ --slave /usr/bin/gcov gcov /usr/local/gcc-14.3/bin/gcov
This command creates symbolic links in /usr/bin/ that point to your source-built compiler, making it available system-wide. The priority number (140 in this example) determines precedence when multiple versions exist. The --slave options ensure that g++ and gcov switch automatically when you change the active GCC version, keeping the entire toolchain synchronized.
Configure Runtime Library Paths
Finally, add the compiler’s runtime libraries to the system linker configuration so programs you compile can find the required shared libraries at runtime. Adjust the version to match your installation:
# Adjust version to match your installation (e.g., gcc-14.3, gcc-13.4)
echo "/usr/local/gcc-14.3/lib64" | sudo tee /etc/ld.so.conf.d/gcc-14.3.conf
sudo ldconfig
The first command creates a configuration file telling the dynamic linker where to find GCC’s libraries. The sudo ldconfig command rebuilds the linker cache, making the libraries immediately available. Without this step, programs you compile with the new GCC may fail at runtime with libstdc++.so.6 or similar missing library errors.
Verify the installation by checking the compiler version:
gcc --version
Expected output (version will match what you compiled):
gcc (GCC) 14.3.0 Copyright (C) 2024 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.
The version string shows plain gcc (GCC) X.X.X without Ubuntu’s package identifiers, distinguishing source builds from repository packages. The version number reflects the release you compiled.
Source-built GCC does not receive automatic security updates through the package manager. This installation method is suitable for development machines and non-production systems. Repeat the source compilation process whenever GNU publishes a newer release that your projects require.
Configure and Switch Between Multiple GCC Versions
Developers working on multiple projects or testing code across compiler versions often need several GCC releases installed simultaneously. The update-alternatives system manages these installations, allowing quick switching between compiler versions without reinstalling packages.
Install Multiple GCC Versions
First, install all GCC versions you need. The following example covers Linux Mint 22 with GCC 11 through GCC 14; adjust the package list based on your release’s availability:
sudo apt install gcc-11 g++-11 gcc-12 g++-12 gcc-13 g++-13 gcc-14 g++-14
For Linux Mint 21, use:
sudo apt install gcc-9 g++-9 gcc-10 g++-10 gcc-11 g++-11 gcc-12 g++-12
Configure GCC Version Priorities
Next, configure update-alternatives to manage these versions. The priority number determines which compiler becomes the system default when you run gcc without a version suffix. Higher numbers take precedence:
Linux Mint 22:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 130 --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 120 --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 110 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
Linux Mint 21:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 120 --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 110 --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 100 --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 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9
These commands configure the highest available GCC version as the default. The --slave options ensure that g++ and gcov versions automatically track the selected gcc version, maintaining consistency across the entire toolchain.
Verify the Default GCC Version
After configuring the priorities, confirm that the expected version is now the default:
gcc --version
Switch Between GCC Versions
If you need to switch to a different GCC version, use the interactive configuration command:
sudo update-alternatives --config gcc
Expected output on Linux Mint 22:
There are 4 choices for the alternative gcc (providing /usr/bin/gcc). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/gcc-14 140 auto mode 1 /usr/bin/gcc-11 110 manual mode 2 /usr/bin/gcc-12 120 manual mode 3 /usr/bin/gcc-13 130 manual mode 4 /usr/bin/gcc-14 140 manual mode Press <enter> to keep the current choice[*], or type selection number:
This displays all configured GCC versions with their priority values. Enter the number corresponding to your desired default compiler. The selection takes effect immediately across the system, and the g++ and gcov versions switch automatically along with gcc.
Test Your GCC Installation
Verify that the GCC compiler functions correctly by creating and compiling a simple C program. This confirms the installed GCC compiler is ready for development projects.
Create a C Program
Create a basic C program using nano or your preferred text editor:
nano hello.c
Add the following code to hello.c:
#include <stdio.h>
int main()
{
printf("Hello, World from LinuxCapable.com!\n");
return 0;
}
Save the file by pressing Ctrl+O, then exit nano by pressing Ctrl+X.
Compile and Run the Program
Compile the program using gcc. The -o flag specifies the output filename:
gcc hello.c -o hello
Run the compiled program:
./hello
Expected output:
Hello, World from LinuxCapable.com!
This output confirms that your GCC compiler is correctly installed and functioning. You can remove the test files with rm hello.c hello when finished.
Troubleshooting Common GCC Issues
Unable to Locate Package Errors
If you encounter “Unable to locate package gcc-14” errors on Linux Mint 21, the package is not available for your release. Linux Mint 21 (based on Ubuntu 22.04) only provides GCC versions 9 through 12. To use GCC 13 or 14 on Mint 21, compile from source using Method 3 or upgrade to Linux Mint 22.
First, verify which GCC versions are available for your system:
apt-cache search "gcc-[0-9]+$" | sort
Expected output on Linux Mint 22 shows GCC 9 through 14, while Linux Mint 21 shows GCC 9 through 12.
cpp Already Registered as Master Alternative
When configuring update-alternatives, you may encounter this error:
update-alternatives: error: alternative cpp can't be slave of gcc: it is a master alternative
This occurs when cpp is already registered as its own master alternative on your system. The simplest solution is to omit cpp from the slave list since GCC invokes the correct preprocessor internally:
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-14
Alternatively, if you need cpp to follow GCC version changes, remove the standalone cpp alternative first:
sudo update-alternatives --remove-all cpp
Then re-run the update-alternatives command including cpp as a slave.
Source Build Compilation Failures
If the source build fails during the configure or make step, verify all prerequisite dependencies installed correctly:
sudo apt install build-essential flex bison libgmp3-dev libmpc-dev libmpfr-dev libisl-dev texinfo curl wget
Check for sufficient free disk space in your build directory:
df -h .
You need at least 4-6 GB of free space during compilation. Insufficient disk space causes cryptic “No space left on device” errors or unexpected build failures.
Runtime Library Errors with GCC 14
Programs compiled with GCC 14 may fail on systems with older libstdc++ versions, producing errors like:
./program: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version 'CXXABI_1.3.15' not found
This occurs when deploying GCC 14-compiled binaries to systems running older GCC versions. Solutions include statically linking the C++ standard library with -static-libstdc++ during compilation, or ensuring target systems have GCC 14 runtime libraries installed.
Remove GCC from Linux Mint
If you need to remove GCC from your system, the cleanup process depends on how you installed the compiler. Follow the section that matches your installation method.
Remove APT-Installed GCC
Remove the build-essential metapackage and any specific GCC versions you installed. Adjust the package list based on what you previously installed:
sudo apt remove build-essential gcc-11 g++-11 gcc-12 g++-12 gcc-13 g++-13 gcc-14 g++-14
sudo apt autoremove
The autoremove command cleans up orphaned dependencies that were installed automatically with GCC packages.
Remove the Ubuntu Toolchain PPA
If you added the Ubuntu Toolchain PPA, remove it along with its GPG key:
sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/ppa -y
sudo apt update
Remove Source-Compiled GCC
Warning: The following commands permanently delete the source-compiled GCC installation. Adjust the version paths to match your installation (e.g.,
gcc-14.3,gcc-13.4). Ensure you have a working alternative compiler (such as the system GCC frombuild-essential) before proceeding.
First, remove the compiler from update-alternatives:
# Adjust path to match your installed version
sudo update-alternatives --remove gcc /usr/local/gcc-14.3/bin/gcc
Then remove the installation directory and linker configuration:
# Adjust paths to match your installed version
sudo rm -rf /usr/local/gcc-14.3
sudo rm /etc/ld.so.conf.d/gcc-14.3.conf
sudo ldconfig
Finally, clean up the build directory if you no longer need it:
# Adjust to match the source directory you created
rm -rf ~/gcc-14.3.0
Conclusion
Your Linux Mint system now has GCC installed with the ability to switch between multiple compiler versions as your projects require. The update-alternatives system provides seamless version management whether you chose repository packages or source compilation. With GCC configured, consider installing Git on Linux Mint for version control, VS Code on Linux Mint for development, or Rust on Linux Mint for systems programming.
This is not working if you are on mint 21 and want g++-14 and gcc-14. There is no package.
Seems only for Linux Mint 22 onwards, sorry I will make a note of this. You would need to download and compile it.