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.

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
Is installing GCC on Linux as complicated as I think it is?
sudo apt install gcc More on reddit.com
๐ŸŒ r/learnprogramming
13
8
June 14, 2017
g++ - How to install g++12 on Ubuntu 20.04? - Unix & Linux Stack Exchange
If you were considering updating to a more recent long-term supported (LTS) version of Ubuntu, it might be a good time to do it now: Ubuntu 22.04LTS allows you to just install GCC 12's g++ using apt install g++-12, done. I predict that unless you have a lot of software depending on obsolete ... More on unix.stackexchange.com
๐ŸŒ unix.stackexchange.com
October 12, 2022
c++ - Install gcc on linux with no root privilege - Stack Overflow
I have access to computer in a public library and I want to try out some C++ and maybe other code. Problem is that there is no g++ installed and I can't install it using packages because I have no ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

Does GCC come pre-installed on Ubuntu?
No. Ubuntu desktop and server images do not include GCC by default. You need to install the build-essential package, which provides GCC, G++, make, and essential development headers.
๐ŸŒ
linuxcapable.com
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
How do I fix "gcc: command not found" on Ubuntu?
Ubuntu does not include GCC by default. Install it with sudo apt install build-essential, which provides gcc, g++, and make. If you installed a specific version like gcc-14, either use the versioned binary (gcc-14) directly or register it with update-alternatives to create the unversioned gcc symlink.
๐ŸŒ
linuxcapable.com
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
Why does "unable to locate package gcc-14" appear on Ubuntu?
This error occurs when the Universe repository is not enabled. GCC versions beyond the default are in the Universe component. Run sudo add-apt-repository universe and sudo apt update, then retry the installation.
๐ŸŒ
linuxcapable.com
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
๐ŸŒ
Ubuntu
documentation.ubuntu.com โ€บ ubuntu-for-developers โ€บ reference โ€บ availability โ€บ gcc
Available GCC versions - Ubuntu for Developers
5 days ago - Develop with GCC ยท Develop with .NET ยท Develop with Java ยท Native compile with GraalVM ยท Checkpoint/Restore with OpenJDK CRaC ยท How-to guides ยท Install and set up Python ยท Install and set up Go ยท Install and set up Rust ยท Install and set up GCC ยท Install and set up .NET ยท
๐ŸŒ
DEV Community
dev.to โ€บ marcosplusplus โ€บ how-to-install-gcc-14-and-use-c23-41od
How to Install GCC 14 and Use C++23 - DEV Community
April 15, 2025 - sudo apt install libstdc++-14-dev libc++-dev libc++abi-dev ยท If you create this code you will need to use the -std=c++23 flag to be able to compile, for example:
Find elsewhere
๐ŸŒ
LinuxCapable
linuxcapable.com โ€บ home โ€บ ubuntu โ€บ how to install gcc on ubuntu (26.04, 24.04, 22.04)
How to Install GCC on Ubuntu (26.04, 24.04, 22.04) - LinuxCapable
1 week ago - Install GCC on Ubuntu 26.04, 24.04 and 22.04 via APT or the Toolchain PPA. Configure multiple versions with update-alternatives.
๐ŸŒ
Ubuntu
documentation.ubuntu.com โ€บ ubuntu-for-developers โ€บ howto โ€บ gcc-setup
How to set up a development environment for GCC on Ubuntu - Ubuntu for Developers
December 2, 2025 - The GNU Compiler Collection (GCC) is a set of compilers for programming languages, including C, C++, Assembly, and many more. It is the ยท de facto standard in Linux environments and is used to compile both the GNU toolchain and the Linux kernel. This guide shows how to install GCC and related tooling, including a build system and debuggers, on Ubuntu Desktop.
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.

๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ is installing gcc on linux as complicated as i think it is?
r/learnprogramming on Reddit: Is installing GCC on Linux as complicated as I think it is?
June 14, 2017 -

Disclaimer: I am not well versed at Linux at all. Please pardon my ignorance.

I'm trying to figure out how to install GCC onto my macbook running Ubuntu 16.04. However after reading through the 6 steps to install GCC outlined on the GCC website I am at a total loss. I understand maybe 50% of the words on these pages. There are so many prerequisites and so many software requirements and so many technical things you have to set up that there is basically no hope in me figuring this out unless I extensively google every other word within the instructions. I would like to install it myself without the use of some sort of installer, but if it's this complicated to do so then I may have quite a bit of googling to do.

My question is this. What are the general guidelines I need to know to install GCC on Linux? I'm not asking for a "step-by-step how-to" guide. I'd just like a general overview on how one goes about installing GCC on their own. I understand I need some required software installed, I need to check and see if my physical CPU is compatible (real confusing), I need figure out in what directory I want to install GCC in, I need to figure out how to build GCC (this is real confusing) and I need to figure out a whole lotta stuff that I don't even know about yet. Perhaps it isn't as hard as it seems. Maybe this way of installing GCC is hard mode that nobody does. Or maybe this is the standard way that everyone uses. I don't know and would greatly appreciate any help or advice you all may have. Thanks!

๐ŸŒ
GitHub
gist.github.com โ€บ zuyu โ€บ 7d5682a5c75282c596449758d21db5ed
Install gcc 6 on Ubuntu ยท GitHub
The error message E: Package 'g++-6' has no installation candidate should come from the fact that after Ubuntu 16.04 LTS, the version of g++ is greater than 6 (g++-7 for 18.04 [source] and g++-9 for 20.04 source). The same remark goes for gcc. A possible workaround would be to download the package source (link Download source package here) and install it from source.
๐ŸŒ
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 - On Ubuntu, installing the GCC Compiler is a simple procedure. Begin by opening the Terminal on your Ubuntu machine. Next, run a command to make sure your package lists are current.
๐ŸŒ
LinuxConfig
linuxconfig.org โ€บ home โ€บ how to install gcc the c compiler on ubuntu 20.04 lts focal fossa linux
How to install GCC the C compiler on Ubuntu 20.04 LTS Focal Fossa Linux
September 21, 2025 - Although you can install the C compiler separately by installation of the gcc package, the recommended way to install the C compiler on Ubuntu 20.04 is by installation of the entire development package build-essential.
Top answer
1 of 1
11

If you were considering updating to a more recent long-term supported (LTS) version of Ubuntu, it might be a good time to do it now: Ubuntu 22.04LTS allows you to just install GCC 12's g++ using apt install g++-12, done. I predict that unless you have a lot of software depending on obsolete dependency libraries, updating your Ubuntu might be the easiest way to get g++12! (You can easily try that out in a podman or docker container, which I'll not go into here.)

If you're stuck to Ubuntu 20.04, I guess the cleanest and most straightforward way of getting g++12 will be to try and backport the 22.04 g++12 package. In that case, you don't have to worry about learning how to build GCC, and how to install a competing g++ that doesn't break all your system by interfering with existing compilers and even worse ABIs. Debian (and Ubuntu as kind-of-downstream of that) have taken the workload of learning that, and you just need to use their tools. Awesome!

Roughly speaking, the procedure to do that is this:

  1. Prepare to build a Debian/Ubuntu package:

    sudo apt update
    sudo apt install -y build-essential fakeroot dpkg-dev devscripts cmake debhelper-compat dh-python equivs
    
  2. Get the package sources. You will need to find the link to the .dsc file on the package page:

    mkdir gcc-12
    cd gcc-12
    dget -u https://URL/OF/DSC/FILE.dsc
    
  3. Install the build dependencies from the .dsc:

    mk-build-deps -i gcc-12*.dsc
    
  4. Build the packages:

    cd gcc-12-somethingsomething
    dpkg-buildpackage -us -uc -ui -d
    

So far for theory. In practice, step 3 will fail โ€“ GCC12 depends on tools whose version shipped by Ubuntu 20.04 is simply too old. Especially, the Debian package says you'd need at least g++11, binutils >= 2.37.

This is really the point where I personally say "If some software that I build needs a bleeding edge C++ compiler, it won't be happy with my Ubuntu 20.04 environment, anyway, and I need to update to a more modern Ubuntu". So, again that's my recommendation; update to Ubuntu 22.04, and then apt install g++-12.

If you want to live with the hassle, you will start to modify the gcc-12-12.*/debian/control and rules.conf, rules2 files to depend on just some g++ instead of g++11, disable ADA support, be less demanding of binutils etc.

However, you can be darn sure that the Debian folks thought about which versions of dependencies to use, and what fixes and backports to include. This is a rocky road. Probably less rocky than a "bare" source build, but it's an easy way to learn way more about GCC than you ever intended, and spend a couple of hours just to start the build.

Honestly, I keep repeating myself, but: if you suddenly find yourself in need of a modern compiler, it's a good time to update to a modern environment. That's way less pain and has way more benefits.

๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ installation โ€บ how to install the latest version of gcc on ubuntu
How to Install the Latest Version of GCC on Ubuntu | Baeldung on Linux
November 17, 2024 - So, we start the process by enabling ... is now installed on the system. Another method to install GCC on Ubuntu employs a PPA (Personal Package Archive)....
๐ŸŒ
Sorush Khajepor
iamsorush.com โ€บ posts โ€บ build-gcc11
Build GCC 11 from source on Ubuntu
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.
๐ŸŒ
Greenwebpage
greenwebpage.com โ€บ home โ€บ blog โ€บ how to install gcc compiler on linux
How to Install GCC Compiler on Linux - Greenwebpage Community
July 4, 2024 - This technical blog will illustrate the necessary steps to install and test GCC on your Linux system (i.e., Ubuntu 24.04). How to Install GCC Compiler on Linux (Ubuntu 24.04)? This technical blog will demonstrate the following topics: How to Install GCC Compiler on Ubuntu 24.04?
๐ŸŒ
DEV Community
dev.to โ€บ nullity โ€บ zai-ubuntu-2004-an-zhuang-gcc-13-1kd1
Install or uninstall gcc 13 on Ubuntu 20.04 - DEV Community
March 22, 2024 - sudo apt update sudo apt install software-properties-common sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt install gcc-13 g++-13