gcc-12 is not available in ubuntu 20.04, so we need to compile it from source code, here are the steps which I borrowed from this video:

  • Step 1: clone gcc source code and checkout gcc-12 branch
$ git clone https://gcc.gnu.org/git/gcc.git gcc-source
$ cd gcc-source/
$ git branch -a
$ git checkout remotes/origin/releases/gcc-12
  • Step 2: make another build dir

Note this is important as running ./configure from within the source directory is not supported as documented here.

$ mkdir ../gcc-12-build
$ cd ../gcc-12-build/
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 3: installing GCC prequisites and run configure again

The missing libraries will be shown in above ./confgiure output, search and install them one by one.

$ apt-cache search MPFR
$ sudo apt-get install libmpfrc++-dev
$ apt-cache search MPC | grep dev
$ sudo apt-get install libmpc-dev
$ apt-cache search GMP | grep dev
$ sudo apt-get install libgmp-dev
$ sudo apt-get install gcc-multilib
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++

An alternative is to run the download_prerequisites script.

 cd gcc-source/
$ ./contrib/download_prerequisites
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 4: compile gcc-12
$ make -j16

Still flex is missing:

$ sudo apt-get install flex
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
$ make -j16
$ make install

Another way is to use Ubuntu 22.04 where gcc-12 is available. In Ubuntu 22.04, gcc-12 can be installed with apt:

$ sudo apt install gcc-12
Answer from lifang on Stack Overflow
🌐
GNU
gcc.gnu.org › gcc-12
GCC 12 Release Series - GNU Project
July 11, 2025 - The GCC developers are pleased to announce the release of GCC 12.5.
Top answer
1 of 4
50

gcc-12 is not available in ubuntu 20.04, so we need to compile it from source code, here are the steps which I borrowed from this video:

  • Step 1: clone gcc source code and checkout gcc-12 branch
$ git clone https://gcc.gnu.org/git/gcc.git gcc-source
$ cd gcc-source/
$ git branch -a
$ git checkout remotes/origin/releases/gcc-12
  • Step 2: make another build dir

Note this is important as running ./configure from within the source directory is not supported as documented here.

$ mkdir ../gcc-12-build
$ cd ../gcc-12-build/
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 3: installing GCC prequisites and run configure again

The missing libraries will be shown in above ./confgiure output, search and install them one by one.

$ apt-cache search MPFR
$ sudo apt-get install libmpfrc++-dev
$ apt-cache search MPC | grep dev
$ sudo apt-get install libmpc-dev
$ apt-cache search GMP | grep dev
$ sudo apt-get install libgmp-dev
$ sudo apt-get install gcc-multilib
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++

An alternative is to run the download_prerequisites script.

 cd gcc-source/
$ ./contrib/download_prerequisites
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
  • Step 4: compile gcc-12
$ make -j16

Still flex is missing:

$ sudo apt-get install flex
$ ./../gcc-source/configure --prefix=$HOME/install/gcc-12 --enable-languages=c,c++
$ make -j16
$ make install

Another way is to use Ubuntu 22.04 where gcc-12 is available. In Ubuntu 22.04, gcc-12 can be installed with apt:

$ sudo apt install gcc-12
2 of 4
16

You can use Homebrew to install pre-built binaries. Follow instructions to install Homebrew at https://brew.sh/, then

brew install gcc for default GCC (currently 11) or brew install gcc@12 for gcc-12.

Note that it may compile missing dependencies.

🌐
GNU
gcc.gnu.org › gcc-12 › changes.html
GCC 12 Release Series — Changes, New Features, and Fixes - GNU Project
December 29, 2025 - An optimization for representing bulk updates to memory (e.g. zero fills) has been removed as it never worked well. In GCC 12 it has been replaced with a simpler and more accurate approach, eliminating many false positives (PR95006).
🌐
Debian
packages.debian.org › sid › gcc-12
Debian -- Details of package gcc-12 in sid
sug: gcc-12-doc (>= 12) documentation for the GNU compilers (gcc, gobjc, g++) sug: gcc-12-locales (>= 12) GCC, the GNU compiler collection (native language support files) sug: gcc-12-multilib [amd64, i386, ppc64, sparc64, x32] GNU C compiler (multilib support) This page is also available in the following languages (How to set the default document language): Български (Bəlgarski) dansk Deutsch español suomi français 한국어 (Hangul) magyar Italiano 日本語 (Nihongo) Nederlands polski Português (pt) Português (br) Русский (Russkij) slovensky svenska Türkçe українська (ukrajins'ka) 中文 (Zhongwen,简) 中文 (Zhongwen,繁) See our contact page to get in touch.
🌐
Ubuntu
launchpad.net › ubuntu › +source › gcc-12
gcc-12 package in Ubuntu
cpp-12: GNU C preprocessor cpp-12-dbgsym: debug symbols for cpp-12 cpp-12-doc: Documentation for the GNU C preprocessor (cpp) g++-12: GNU C++ compiler g++-12-dbgsym: debug symbols for g++-12 g++-12-multilib: GNU C++ compiler (multilib support) ...
🌐
Red Hat
developers.redhat.com › articles › 2022 › 04 › 25 › new-c-features-gcc-12
New C++ features in GCC 12 | Red Hat Developer
October 8, 2024 - Version 12 of GCC implements much of the recent C++ standard, allows a number of previously prohibited constructs, and fixes some problematic behaviors.
🌐
DevDocs
devdocs.io › gcc~12
DevDocs — GCC 12 documentation
GCC 12.2.0 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
🌐
SUSE
documentation.suse.com › sbp › devel-tools › html › SBP-GCC-12 › index.html
Advanced Optimization and New Capabilities of GCC 12 | SUSE Linux Enterprise Server 15 SP4
June 14, 2023 - GCC 12 comes with many new features, such as implementing parts of the most recent versions of specifications of various languages (especially C2X, C++20, C++23) and their extensions (OpenMP, OpenACC), supporting new capabilities of a wide range ...
Find elsewhere
🌐
Intel
intel.com › content › www › us › en › developer › articles › technical › building-innovation-and-performance-with-gcc12.html
Build Innovation and Performance with GCC* 12
The GNU Compiler Collection (GCC)* team at Intel has actively worked with the GCC community to contribute innovative and performance enhancements (general and x86-specific) into GCC 12. A very-cheap cost model is used to enable vectorization at the -O2 optimization level, bringing vectorization performance gains to O2 users, with a small impact to the code size.
🌐
Arm Community
community.arm.com › arm-community-blogs › b › tools-software-ides-blog › posts › gcc-12
Arm Community
May 10, 2022 - With GCC 12, we have continued to enhance GCC’s intrinsics support. This year has focused on starting to migrate intrinsics functions from RTL definitions into GIMPLE to allow the front end of the compiler to understand the semantics of the instructions. The goal here is to effectively remove the physical arm_Neon.h file from the compiler source tree entirely and instead synthesis the header entirely in the compiler itself.
🌐
Kali Linux
pkg.kali.org › pkg › gcc-12
gcc-12 - Kali Linux Package Tracker
source: gcc-12 (main) version: 12.5.0-9 · maintainer: Debian GCC Maintainers (archive) uploaders: Matthias Klose · arch: all any · std-ver: 4.7.3 · VCS: Git (Browse) versions · [pool directory] kali-roll: 12.5.0-9 · kali-dev: 12.5.0-9 · deb-test: 12.5.0-9 ·
🌐
GNU
gcc.gnu.org › onlinedocs › gcc-12.1.0 › gcc
Top (Using the GNU Compiler Collection (GCC))
This manual documents how to use the GNU compilers, as well as their features and incompatibilities, and how to report bugs. It corresponds to the compilers (GCC) version 12.1.0. The internals of the GNU compilers, including how to port them to new targets and some information about how to ...
🌐
GNU
gcc.gnu.org › gcc-12 › criteria.html
GCC 12 Release Criteria - GNU Project
GCC supports several programming languages, including Ada, C, C++, Fortran, Objective-C, Objective-C++, Go, and D. For the purposes of making releases, however, we will consider primarily C and C++, as those are the languages used by the vast majority of users.
🌐
Linux From Scratch
linuxfromscratch.org › blfs › view › 11.2 › general › gcc.html
GCC-12.2.0
If you have installed additional packages such as Valgrind and GDB, the GCC part of the testsuite will run more tests than in LFS. Some of those will report FAIL and others XPASS (pass when expected to FAIL). As of gcc-12.1.0, about 90 FAIL occur in the “guality” suite, as well as miscellaneous failures throughout the rest of the test suite.
🌐
GNU
gcc.gnu.org › onlinedocs › 12.2.0
GCC 12.2 manuals - GNU Project
GCC 12.2 Manual (also in PDF or PostScript or an HTML tarball)
🌐
Debian
tracker.debian.org › pkg › gcc-12
gcc-12 - Debian Package Tracker
[2025-04-14] Accepted gcc-12 12.2.0-14+deb12u1 (source) into proposed-updates (Debian FTP Masters) (signed by: Emanuele Rocca)
🌐
Phoronix
phoronix.com › news › GCC-12.5-Released
GCC 12.5 Compiler Released To End Out The GCC 12 Series With 241+ Bug Fixes - Phoronix
July 11, 2025 - For those who seldom update to new compiler versions, GCC 12.5 was released today as the newest and final update to the GCC 12 compiler that debuted back in 2022. GCC 12.5 is the last planned update to the GCC 12 series with GCC 15 being the newest and greatest compiler release that debuted ...