I'm still on Ubuntu 22.04 LTS but needed g++14. The sudo apt-get gcc-14 did not work for me, as it installed clang++14 for some reason (perhaps a misconfiguration on my part). What did work for me was following the instructions I found at https://www.dedicatedcore.com/blog/install-gcc-compiler-ubuntu/

The steps I took:

sudo apt install build-essential
sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
wget https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
tar -xf gcc-14.1.0.tar.gz
cd gcc-14.1.0
./configure -v --build=$(uname -m)-linux-gnu --host=$(uname -m)-linux-gnu --target=$(uname -m)-linux-gnu --prefix=/usr/local/gcc-14.1.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-14.1.0
make
sudo make install

And if you would like to make it the default:

sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-14.1.0/bin/g++-14.1.0 14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-14.1.0/bin/gcc-14.1.0 14

After that, g++ showed I was running version 14.1.0. I was then able to compile my project that included some c++20/23 features that were not in the previous versions of g++ (chrono/format).

Answer from John Jones on askubuntu.com
Top answer
1 of 5
20

I'm still on Ubuntu 22.04 LTS but needed g++14. The sudo apt-get gcc-14 did not work for me, as it installed clang++14 for some reason (perhaps a misconfiguration on my part). What did work for me was following the instructions I found at https://www.dedicatedcore.com/blog/install-gcc-compiler-ubuntu/

The steps I took:

sudo apt install build-essential
sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
wget https://ftp.gnu.org/gnu/gcc/gcc-14.1.0/gcc-14.1.0.tar.gz
tar -xf gcc-14.1.0.tar.gz
cd gcc-14.1.0
./configure -v --build=$(uname -m)-linux-gnu --host=$(uname -m)-linux-gnu --target=$(uname -m)-linux-gnu --prefix=/usr/local/gcc-14.1.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-14.1.0
make
sudo make install

And if you would like to make it the default:

sudo update-alternatives --install /usr/bin/g++ g++ /usr/local/gcc-14.1.0/bin/g++-14.1.0 14
sudo update-alternatives --install /usr/bin/gcc gcc /usr/local/gcc-14.1.0/bin/gcc-14.1.0 14

After that, g++ showed I was running version 14.1.0. I was then able to compile my project that included some c++20/23 features that were not in the previous versions of g++ (chrono/format).

2 of 5
15

GCC-14 (and G++-14) is available in the Universe repository for Ubuntu 24.04, as evident in the Ubuntu Package archive.

It is equally evident that this package is not available for Ubuntu 22.04, so installing this on 22.04 will require some third-party interference, or you have to compile it yourself.

See here on how to enable the Universe repositories.

🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › howto › gcc-setup
How to set up a development environment for GCC on Ubuntu - Ubuntu for Developers
2 weeks ago - This guide shows how to install GCC and related tooling, including a build system and debuggers, on Ubuntu Desktop.
Discussions

linux - how to install gcc-12 on ubuntu - Stack Overflow
$ sudo apt search gcc-12 Sorting... Done Full Text Search... Done $ uname -a Linux Han 5.10.81.1-microsoft-standard-WSL2 #1 SMP Mon Nov 22 18:52:15 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux I am usi... More on stackoverflow.com
🌐 stackoverflow.com
Ubuntu 18.10 - how to install a specific version of gcc - Stack Overflow
Disclaimer: I have searched and read similar posts and they do not answer my question. I am running Ubuntu 18.10 and need to install gcc 8.2.0 to build kernel modules. apt-get wants to install 8.3 More on stackoverflow.com
🌐 stackoverflow.com
Ubuntu 24.04 and VirtualBox
Just tried on 7.0.18, now is fixed More on reddit.com
🌐 r/Ubuntu
8
6
April 27, 2024
How can I run windows.h crap in Linux
Why would you need windows.h to learn C++? That header contains windows-specific stuff, which you need (only) when you want to do C++ programming *specifically for windows*. If that is what you want, get a windows machine. If not, remove the include, and if that gives you problems solve those, or abandon the example because it is windows-specific. More on reddit.com
🌐 r/cpp_questions
4
3
November 6, 2020
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to install gcc compiler on ubuntu
How to Install GCC Compiler on Ubuntu {3 Simple Methods}
February 20, 2025 - This guide will show you how to install GCC on Ubuntu and start compiling code on your system.
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › tutorials › gcc-use
Develop with GCC on Ubuntu - Ubuntu for Developers
2 weeks ago - This tutorial shows how to build and debug C programs on Ubuntu using GCC and GDB. For instructions on installing GCC and related tooling (including IDEs, debuggers, and the build system), see the dedicated guide on How to set up a development environment for GCC on Ubuntu.
🌐
GitHub
gist.github.com › zuyu › 7d5682a5c75282c596449758d21db5ed
Install gcc 6 on Ubuntu · GitHub
sudo apt update 4.sudo apt-get install gcc-6 g++-6 -y ... vim is just a text editor. You can whether install it using sudo apt install vim or use another one, as nano. ... Hi, This has been useful for me, so I'll chip in.
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › reference › availability › gcc
Available GCC versions - Ubuntu for Developers
April 5, 2026 - Installing Ubuntu Desktop for developers · Using Git version control on Ubuntu · Packaging software · Introduction to the .NET toolchain · Debugging with .NET · GraalVM native compilation · Contribute documentation · Back to top · Contribute to this page · This page lists GCC versions available in Ubuntu releases.
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.

Find elsewhere
🌐
LinuxCapable
linuxcapable.com › home › ubuntu › how to install gcc on ubuntu 26.04, 24.04 and 22.04
How to Install GCC on Ubuntu 26.04, 24.04 and 22.04 - LinuxCapable
2 weeks ago - Install GCC on Ubuntu 26.04, 24.04 and 22.04 via APT or the Toolchain PPA. Configure multiple versions with update-alternatives.
🌐
Learn Ubuntu
learnubuntu.com › install-gcc
How to Install GCC on Ubuntu
December 5, 2022 - gcc is required for compiling C and C++ code on Ubuntu. You can install it directly or with other dev tools with the build-essential package.
🌐
Linux Hint
linuxhint.com › install_gcc_ubuntu
Install GCC on Ubuntu – Linux Hint
So, you can easily GCC on Ubuntu using the APT package manager. First, update the APT package repository cache with the following command: ... The APT package repository cache should be updated. Now, install the build-essential package with the following command:
🌐
Cherry Servers
cherryservers.com › home › blog › linux › how to install gcc on ubuntu 22.04 [and compile a c program]
How to Install GCC on Ubuntu 22.04 [and Compile a C Program] | Cherry Servers
November 7, 2025 - This article will show you how to install GCC on Ubuntu 22.04, compile a C program, and briefly explain the GCC compiler.
🌐
nixCraft
cyberciti.biz › nixcraft › howto › linux › ubuntu linux install gnu gcc compiler and development environment
Ubuntu Linux Install GNU GCC Compiler and Development Environment - nixCraft
August 11, 2025 - Explains how to install development tools such as GNU GCC C/C++ compiler and related tools on a Ubuntu Linux using the APT command.
🌐
Linuxize
linuxize.com › home › gcc › how to install gcc (build-essential) on ubuntu 20.04
How to Install GCC (build-essential) on Ubuntu 20.04 | Linuxize
June 4, 2020 - The default Ubuntu repositories contain a meta-package named “build-essential” that includes the GNU compiler collection, GNU debugger, and other development libraries and tools required for compiling software. To install the Development Tools packages, run the following command as root or user with sudo privileges : ... The command installs a lot of packages, including gcc, g++ and make.
🌐
DedicatedCore
dedicatedcore.com › home › how to install gcc compiler on ubuntu 22.04
How to Install GCC Compiler on Ubuntu 22.04 - DedicatedCore Blog
January 24, 2025 - This guide will show you how to install GCC on a Ubuntu. A step-by-step so that you have all the tools you need to start writing and creating software immediately. For a seamless installation process of the powerful programming language Go (Golang) check.
🌐
Medium
medium.com › @ihouelecaurcy › how-to-check-and-install-gcc-on-linux-complete-developer-guide-98697e2ab78f
How to Check and Install GCC on Linux: Complete Developer Guide | by Ihouele Caurcy | Medium
July 24, 2025 - # Release build gcc -O2 -DNDEBUG program.c -o program# Check supported optimizations gcc --help=optimizers · # Install specific versions (Ubuntu) sudo apt install gcc-9 gcc-10 gcc-11
🌐
LinuxConfig
linuxconfig.org › home › how to install gcc the c compiler on ubuntu 22.04 lts jammy jellyfish linux
How to install GCC the C compiler on Ubuntu 22.04 LTS Jammy Jellyfish Linux
January 8, 2024 - $ sudo apt update $ sudo apt install build-essential · DO YOU NEED MULTIPLE C AND/OR C++ COMPILER VERSIONS? Visit our other tutorial on How to switch between multiple GCC and G++ compiler versions on Ubuntu 22.04 to see how to install multiple ...
🌐
Sorush Khajepor
iamsorush.com › posts › build-gcc11
Build GCC 11 from source on Ubuntu - Sorush Khajepor
You need a C and C++ compiler found in $PATH to compile the new version. Try gcc and g++ in a terminal, if not there, install the system default ones ... Go to GCC releases on GitHub, download the latest version in the format of tar.gz. Here, I install GCC 11.1.
🌐
Linuxize
linuxize.com › home › gcc › how to install gcc compiler on ubuntu 18.04
How to Install GCC Compiler on Ubuntu 18.04 | Linuxize
October 31, 2019 - We will show you how to install the distro stable version and the latest version of GCC. The same instructions apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS.
🌐
Namehero
namehero.com › blog › how-to-install-gcc-on-ubuntu
How To Install GCC On Ubuntu
November 4, 2024 - Press Ctrl+Alt+T on your keyboard to open the Ubuntu terminal. This is where we’ll run the installation commands. ... Before we install GCC, let’s ensure that our package lists are up to date.