{"id":51868,"date":"2026-08-17T13:15:50","date_gmt":"2026-08-17T13:15:50","guid":{"rendered":"https:\/\/ubuntuhandbook.org\/?p=51868"},"modified":"2026-08-17T13:15:50","modified_gmt":"2026-08-17T13:15:50","slug":"install-gcc-16-in-ubuntu-24-04-22-04-or-20-04","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2026\/08\/install-gcc-16-in-ubuntu-24-04-22-04-or-20-04\/","title":{"rendered":"How to Install GCC 16 in Ubuntu 24.04, 22.04, or 20.04"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-51869\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc-icon-250x250.webp\" alt=\"\" width=\"250\" height=\"250\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc-icon-250x250.webp 250w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc-icon-300x300.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc-icon-700x700.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc-icon-768x768.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc-icon.webp 1200w\" sizes=\"auto, (max-width: 250px) 100vw, 250px\" \/><\/p>\n<p>This is a step by step beginner&#8217;s guide shows how to install the GCC 16 compiler in Ubuntu 24.04 \/ Linux Mint 22.x, Ubuntu 22.04, Ubuntu 20.04, and even the old Ubuntu 18.04.<\/p>\n<p>GCC 16 is so far the latest major version of the GNU Compiler Collection. It&#8217;s available in Ubuntu 26.04 repository but non-default.<\/p>\n<p><!--more--><\/p>\n<div id=\"attachment_51870\" style=\"width: 620px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-51870\" class=\"size-large wp-image-51870\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc16-resolute-700x541.webp\" alt=\"\" width=\"610\" height=\"471\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc16-resolute-700x541.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc16-resolute-300x232.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcc16-resolute.webp 748w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><p id=\"caption-attachment-51870\" class=\"wp-caption-text\">Ubuntu 26.04 default to GCC 15, while GCC 16 is available for choice<\/p><\/div>\n<h3>What&#8217;s New in GCC 16<\/h3>\n<p>GCC 16 defaults to C++20 (<code>-std=gnu++20<\/code>), and features early C++26 support including <code>std::simd<\/code>, <code>std::inplace_vector<\/code>, <code>std::copyable_function<\/code>, <code>std::function_ref<\/code>, <code>std::optional&lt;T&amp;&gt;<\/code>, and more.<\/p>\n<p>It added support Intel Wildcat Lake and the upcoming AMD Zen 6, and Intel Nova Lake CPUs support, as well as new experimental Algol 68 compiler.<\/p>\n<p>It as well improved C++ error messages, including making hierarchical\/nested diagnostics the default, added initial support for exceptions and Named Return Value Optimization, and, expanded <code>_BitInt<\/code> support to more architectures. See <a href=\"https:\/\/gcc.gnu.org\/gcc-16\/changes.html\" target=\"_blank\">this page<\/a> for more changes in GCC 16.<\/p>\n<h3>Install GCC 16 in Ubuntu via PPA<\/h3>\n<p>As mentioned Ubuntu 26.04 includes GCC 16 in system repository. User of the LTS may directly run the <code>apt install<\/code> command below to install it.<\/p>\n<p>For current Ubuntu 24.04, Ubuntu 22.04 LTS, and even the old Ubuntu 20.04\/18.04 LTS, there&#8217;s an <a href=\"https:\/\/launchpad.net\/~ubuntu-toolchain-r\/+archive\/ubuntu\/test\" target=\"_blank\">&#8220;official&#8221; PPA<\/a> that contains the compiler for all supported CPU architecture types (e.g., <code>amd64<\/code>, <code>arm64\/armhf<\/code>, <code>ppc64el<\/code>, <code>riscv64<\/code>, <code>s390x<\/code>).<\/p>\n<p>Not only GCC 16, the PPA also include GCC 13, GCC 14, and GCC 15 that the previous Ubuntu LTS releases don&#8217;t have.<\/p>\n<p><b>NOTE: The PPA is maintained by Ubuntu Developer who&#8217;s behind the official Ubuntu-provided GCC compiler. It&#8217;s however marked as test build, meaning not officially support by Ubuntu.<\/b><\/p>\n<p><b>1.<\/b> To add the PPA, press <code>Ctrl+Alt+T<\/code> on keyboard to launch a terminal window, then run command:<\/p>\n<pre>sudo add-apt-repository ppa:ubuntu-toolchain-r\/test<\/pre>\n<p><i>Type user password when it asks (no visual feedback, just type in mind) and hit Enter to continue.<\/i><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcctool-ppa-700x374.webp\" alt=\"\" width=\"610\" height=\"326\" class=\"aligncenter size-large wp-image-51872\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcctool-ppa-700x374.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcctool-ppa-300x160.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/gcctool-ppa.webp 750w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<p><b>2.<\/b> If you follow this tutorial in Linux Mint, then either use Software Sources to add PPA, or run the command below to refresh cache after added the PPA.<\/p>\n<pre>sudo apt update<\/pre>\n<p>While Ubuntu now automatically refresh cache when adding PPA via the <code>add-apt-repository<\/code> command.<\/p>\n<p><b>3.<\/b> Finally GCC 16 by running command:<\/p>\n<pre>sudo apt install gcc-16 g++-16<\/pre>\n<p>For choice, you may also install the <code>ga68-16<\/code> Algol 68 compiler, <code>gccgo-16<\/code> Go compiler, as well as other GNU compilers.<\/p>\n<p>And, you may replace number <b>16<\/b> accordingly (to 15, 14, 13, etc) to install other GCC compiler versions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/apt-gcc16-700x516.webp\" alt=\"\" width=\"610\" height=\"450\" class=\"aligncenter size-large wp-image-51871\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/apt-gcc16-700x516.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/apt-gcc16-300x221.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/apt-gcc16.webp 723w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<h3>How to Use GCC 16<\/h3>\n<p>After installed the new version of GNU Compiler, you may run the similar command below to make use of it:<\/p>\n<pre>CC=gcc-16 CXX=g++-16 cmake ..<\/pre>\n<p>or use <code>make CC=gcc-16 CXX=g++-16<\/code>.<\/p>\n<p>Or, run the command below to set environment variables, to temporarily use GCC 16 in the current shell (until you close the terminal).<\/p>\n<pre>export CC=gcc-16<\/pre>\n<pre>export CXX=g++-16<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/export-gcc16-700x516.webp\" alt=\"\" width=\"610\" height=\"450\" class=\"aligncenter size-large wp-image-51873\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/export-gcc16-700x516.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/export-gcc16-300x221.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/export-gcc16.webp 723w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<h3>Set GCC 16 as default (Optional)<\/h3>\n<p>The last step shows you how to temporarily use GCC 16 in terminal. If you want, you can set GCC 16 as default compiler.<\/p>\n<p><b>1.<\/b> First, run the commands below to install GCC 16 as an alternative to default GCC\/G++:<\/p>\n<pre>sudo update-alternatives --install \/usr\/bin\/gcc gcc \/usr\/bin\/gcc-16 10<\/pre>\n<pre>sudo update-alternatives --install \/usr\/bin\/g++ g++ \/usr\/bin\/g++-16 10<\/pre>\n<p><b>2.<\/b> Next, add the previous default GCC as alternatives:<\/p>\n<pre>sudo update-alternatives --install \/usr\/bin\/gcc gcc \/usr\/bin\/gcc-11 100<\/pre>\n<pre>sudo update-alternatives --install \/usr\/bin\/g++ g++ \/usr\/bin\/g++-11 100<\/pre>\n<p>Here you need to replace number <b>11<\/b> depends on your previous default GCC version. It&#8217;s gcc-11 for 22.04, gcc-13 for 24.04, gcc-7 for 18.04.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/install-gccalternatives-700x237.webp\" alt=\"\" width=\"610\" height=\"207\" class=\"aligncenter size-large wp-image-51874\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/install-gccalternatives-700x237.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/install-gccalternatives-300x102.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/install-gccalternatives-768x260.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/install-gccalternatives.webp 894w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><br \/>\n<b>3.<\/b> Finally, run the commands below one by one to configure the default GCC:<\/p>\n<pre>sudo update-alternatives --config gcc<\/pre>\n<pre>sudo update-alternatives --config g++<\/pre>\n<p>And you can re-run the last 2 commands at any time to restore the default GCC to the previous version.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/config-gcc-700x485.webp\" alt=\"\" width=\"610\" height=\"423\" class=\"aligncenter size-large wp-image-51875\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/config-gcc-700x485.webp 700w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/config-gcc-300x208.webp 300w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/config-gcc-768x532.webp 768w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2026\/08\/config-gcc.webp 795w\" sizes=\"auto, (max-width: 610px) 100vw, 610px\" \/><\/p>\n<h3>Uninstall:<\/h3>\n<p>Before uninstalling GCC 16, re-run the last 2 commands and set the default GCC\/G++ to the previous default version.<\/p>\n<p>Then, run the command below to uninstall GCC 16:<\/p>\n<pre>sudo apt remove --autoremove gcc-16 g++-16<\/pre>\n<p>And, remove the PPA by running command:<\/p>\n<pre>sudo add-apt-repository --remove ppa:ubuntu-toolchain-r\/test<\/pre>\n<p>Finally, refresh cache via <code>sudo apt update<\/code>.<\/p>\n<p><b>Tips:<\/b> If you removed GCC 16, but the default version is not set back, then try running the commands below to restore:<\/p>\n<pre>sudo update-alternatives --set gcc \/usr\/bin\/gcc-11<\/pre>\n<pre>sudo update-alternatives --set g++ \/usr\/bin\/g++-11<\/pre>\n<p>Also, replace number <b>11<\/b> with 7 for 18.04, 13 for 24.04, 15 for 26.04.<\/p>","protected":false},"excerpt":{"rendered":"<p>This is a step by step beginner&#8217;s guide shows how to install the GCC 16 compiler in Ubuntu 24.04 \/ Linux Mint 22.x, Ubuntu 22.04, Ubuntu 20.04, and even the old Ubuntu 18.04. GCC 16 is so far the latest major version of the GNU Compiler Collection. It&#8217;s available in Ubuntu 26.04 repository but non-default.<\/p>\n","protected":false},"author":1,"featured_media":51869,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[2086],"class_list":["post-51868","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-programming"],"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/51868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=51868"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/51868\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media\/51869"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=51868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=51868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=51868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}