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.

๐ŸŒ
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 - $ /usr/local/gcc-14.2.0/bin/gcc-14.2.0 --version gcc-14.2.0 (GCC) 14.2.0 ยท Visibly, the latest version is now installed on the machine. In this article, weโ€™ve provided a detailed explanation of three methods that we can use to install GCC on Ubuntu.
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
๐ŸŒ
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 - The system confirms GCC version 14.2.0 is installed. ... This guide showed how to install the GCC compiler on Ubuntu using three different methods.
๐ŸŒ
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.
๐ŸŒ
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
December 6, 2023 - If apt search gcc-14 shows no results, enable the Universe repository with sudo add-apt-repository universe && sudo apt update before installing GCC 14. ... Ubuntu 22.04 ships GCC 11 as the default.
๐ŸŒ
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 - g++ --version g++ (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.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. Advantages of doing it the way above instead of just changing the symbolic link: Doesn't break the system. Can easily switch between versions. Avoids conflicts with apt/dpkg. If you are having problems with your LSP clangd also install these libraries for compatibility with Clang:
๐ŸŒ
Reddit
reddit.com โ€บ r/ubuntu โ€บ install gcc 14 in non-debug mode in ubuntu 24.04
r/Ubuntu on Reddit: Install GCC 14 in non-debug mode in Ubuntu 24.04
July 29, 2024 - My current GCC version is 13.2.0-7 ... in Ubuntu 24.04. But there are some issues when using the -fsanitize=address flag as shown in this Possible Bug in GCC Sanitizers? post. The bug causes around half of the compilations to fail. The solution given was to upgrade gcc version after 13.2.1-4 in which the issue has been fixed. A temporary fix is to disable ASLR. Since I tend to use the-fsanitize=address flag often to help catch errors, I wanted to install gcc-14 which is available ...
Find elsewhere
๐ŸŒ
Scholtyssek
scholtyssek.org โ€บ en โ€บ gcc-mit-c14-unterstuetzung-fuer-ubuntu-mint-installieren
Install GCC with C++14 support on Ubuntu/Mint โ€“ scholtyssek.org
sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install g++-4.9 ยท After the installation, the compiler can be used by this command: ... The default compiler will not be updated. You can see this because the g++ symlink points to the old g++ version: ... ...
๐ŸŒ
CyberPanel
cyberpanel.net โ€บ blog โ€บ install-gcc-on-ubuntu
How To Install GCC On Ubuntu: Easiest Methods Explained!
March 18, 2025 - 7. Start the GCC build process using the make command: ... This process can be resource-intensive and may take some time. The j3 option tells the system to use three cores for the build.
๐ŸŒ
GitHub
gist.github.com โ€บ application2000 โ€บ 73fd6f4bf1be6600a2cf9f56315a2d91
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04) ยท GitHub
As of today May 25th 2020 on Ubuntu 20.04 your list of commands does not install the latest 10.1.0. Instead, it installs the older "10.0.1 20200416 (experimental) (Ubuntu 10-20200416-0ubuntu1)" -- because the older version is the only one there at that PPA site for release "Focal". The other package "10.1.0-2ubuntu1~18.04" is for "Bionic" not "Focal". On 20.04, run the following commands today (May 25th, 2020) and it shows that none of the packages are 10.1: sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt list -a gcc-10
๐ŸŒ
Ubuntu
launchpad.net โ€บ ubuntu โ€บ +source โ€บ gcc-14
gcc-14 package : Ubuntu
There are no projects registered in Launchpad that are a potential match for this source package. Can you help us find one? Other versions of 'gcc-14' in untrusted archives. The following unsupported and untrusted Personal Archives (PPAs) provide packages of 'gcc-14': Toolchain builds owned by PPA for Ubuntu Toolchain Uploads (restricted)
๐ŸŒ
Ubuntu
documentation.ubuntu.com โ€บ ubuntu-for-developers โ€บ reference โ€บ availability โ€บ gcc
Available GCC versions - Ubuntu for Developers
5 days ago - Ubuntu GCC (deb) packages:,,, Ubuntu version, available GCC versions, gcc-defaults version,,, 25.10 (Questing Quokka), 11, 12, 13, 14, 15, 15,, 25.04 (Plucky Puffin), 11, 12, 13, 14, 15, 14,, 24.10...
๐ŸŒ
Ubuntu Shell
ubuntushell.com โ€บ install-gcc-on-ubuntu
How to Install GCC on Ubuntu 25.04: A Step-By-Step Guide
November 13, 2025 - In this article, you'll learn how to install GCC on Ubuntu, followed by writing and compiling basic C/C++ programs.
Top answer
1 of 5
240

The best way to correctly install gcc-4.9 and set it as your default gcc version use:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

The --slave, with g++, will cause g++ to be switched along with gcc, to the same version. But, at this point gcc-4.9 will be your only version configured in update-alternatives, so add 4.8 to update-alternatives, so there actually is an alternative, by using:

sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8

Then you can check which one that is set, and change back and forth using:

sudo update-alternatives --config gcc

If you have an issue with update-alternatives gcc priority 60 not being higher than previous versions installed you can use the previous update-alternatives --config gcc command to check installed versions and use:

sudo update-alternatives --remove gcc

Or:

sudo update-alternatives --remove-all gcc

NOTE: You could skip installing the PPA Repository and just use /usr/bin/gcc-4.9-base but I prefer using the fresh updated toolchains.


For GCC 5.X or 6, the packages (and correspondingly, the commands) are just called gcc-5, gcc-6, etc. This is due to the change in GCC's version scheme, where 5.1 is the first GCC 5 release, and future 5.X releases are for bug fixes.

2 of 5
63

Ultimate mega master compatibility table

OK let's do this:

                  GCC                              clang
        +-------------------------------------+-------------------------------------------------+
        | 15 14 13 12 11 10  9  8  7  6  5  4 | 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5 |
+-------+-------------------------------------+-------------------------------------------------+
| 25.10 |  D  M  M  M  M                      |  D  M  M  M                                     |
| 25.04 |     D  M  M  M                      |  D  M  M  M                                     |
| 24.10 |     D  M  M  M                      |     D  M  M  M  M  M                            |
| 24.04 |     M  D  M  M  M  M                |        D  M  M  M  M                            |
| 23.10 |        D  M  M  M  M                |           M  D  M  M  M                         |
| 23.10 |        D  M  M  M  M                |              D  M  M  M                         |
| 23.04 |        M  D  M  M  M                |              M  D  M  M                         |
| 22.10 |           D  M  M  M                |                 D  M  M                         |
| 22.04 |        P  M  D  M  M                |                    D  M  M  M                   |
| 21.10 |              D  M  M  M             |                       D  M  M  M  M             |
| 21.04 |              M  D  M  M  M          |                          D  M  M  M             |
| 20.10 |                 D  M  M  M          |                             D  M  M  M  M  M    |
| 20.04 |                 P  D  M  M          |                                D  M  M  M  M    |
| 19.10 |                    D  M  M          |                                                 |
| 19.04 |                    M  D  M  M       |                                                 |
| 18.10 |                       D  M  M  M    |                                                 |
| 18.04 |                 P  P  M  D  M  M    |                                   M  M  M  D  M |
| 16.04 |                    P  P  P  P  D  M |                                                 |
+-------+-------------------------------------+-------------------------------------------------+
  • D: Default GCC

    sudo apt-get update
    sudo apt-get install gcc g++
    gcc --version
    

    Whatever the gcc package aliases to: https://packages.ubuntu.com/search?keywords=gcc and also present in manifests: How do I list the default installed packages?

  • M: Present in Main repo

    sudo apt-get update
    sudo apt-get install gcc-X g++-X
    gcc-X --version
    

    All Ubuntu versions that have a hit for a given GCC version, e.g. for GCC 7: https://packages.ubuntu.com/search?keywords=gcc-7 or clang 7 https://packages.ubuntu.com/search?keywords=clang-7

    The minor versions of these packages can get updated from time to time within a single Ubuntu version (on the . revisions?), e.g. 8.3.0 to 8.4.0 so we are not keeping track of that.

  • P: ppa:ubuntu-toolchain-r/test, which is owned by Ubuntu people and therefore can be trusted to not be a virus, although it is possibly unstable:

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test
    sudo apt-get update
    sudo apt-get install gcc-X g++-X
    gcc-X --version
    

    Full list: https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test

    The minor versions of these packages can get updated from time to time, e.g. 8.3.0 to 8.4.0.

Blank spaces on the table mean either "no package available" or "I didn't bother to check". Notably I've not been looking into PPA packages too thoroughly. Edits accepted.

All the questions:

  • install gcc-9 on Ubuntu 18.04?
  • How to install gcc-7 or clang 4.0?
  • install gcc-9 on Ubuntu 18.04?
  • What are the GCC and clang versions available in Ubuntu 18.04?

How to set a non-default GCC as the default?

E.g., you installed /usr/bin/gcc-7 but you want to use that instead of /usr/bin/gcc when you run gcc main.c.

Use sudo update-alternatives as mentioned in other answers: https://askubuntu.com/a/581497/52975 It creates the required symlinks for you.

See also: What exactly does `update-alternatives` do?

How to build your own toolchain from source

If even the PPA is not old/new enough for you, see this:

  • https://stackoverflow.com/questions/847179/multiple-glibc-libraries-on-a-single-host/52454603#52454603
  • https://stackoverflow.com/questions/26305738/can-i-build-gcc-for-arm-with-an-x64-one/26306591#26306591

Older GCC version questions

  • Ubuntu 20.04 - gcc version lower than gcc-7
  • How to use an older version of GCC
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 ../
$ 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.

๐ŸŒ
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 - This guide shows how to install GCC and related tooling, including a build system and debuggers, on Ubuntu Desktop. The GCC toolchain, including past versions and cross-compilers for different architectures, is included in the Ubuntu package repository. The gcc package provides the default version of GCC for your platform. gcc runs the C compiler and g++ runs the C++ compiler. ... gcc (Ubuntu 14...
๐ŸŒ
Ask Ubuntu
askubuntu.com โ€บ questions โ€บ 1541622 โ€บ how-to-install-gcc-14-and-g-14-on-ubuntu-22-04
apt - How to install gcc-14 and g++-14 on Ubuntu 22.04? - Ask Ubuntu
sudo ln -s /usr/local/gcc-14/bin/g++ /usr/local/bin/g++-14 sudo ln -s /usr/local/gcc-14/bin/gcc /usr/local/bin/gcc-14 ... Alternatively, you can do something similar with update-alternatives. sudo update-alternatives --install /usr/bin/g++ g++ ...
๐ŸŒ
YouTube
youtube.com โ€บ programmingknowledge
How to Install GCC and G++ Compiler on Ubuntu 24.04 LTS (Linux) (2024) - YouTube
How to Install GCC and G++ Compiler on Ubuntu 24.04 LTS (Linux)In this tutorial, we will guide you through the steps to install the GCC and G++ compilers on ...
Published ย  July 9, 2024
Views ย  2K
Top answer
1 of 2
5

I am currently using Ubuntu 22.04 but frustrated that I can't load the latest {something}

First step: You're using Ubuntu 22.04, which is already the old long-term stable releas of Ubuntu. The immediate first thing you should do before even considering switching distro is updating yours; to 24.04, specifically. If you feel the need to install very recent software more often, you won't benefit from long-term supported distro releases, so the most recent version of Ubuntu (as of now, 24.10, soon 25.04) and biannual updates would serve you better (or one of the even more fast-moving distros, like Fedora, or even rolling release distros).

That instantly makes sudo apt install gcc-14 g++-14 gfortran-14 (depending on whether you need C, C++ and/or Fortran compilers) give you gcc 14.2.0; beautifully installed side-by-side with any other Ubuntu-installed gcc version, selectable by specifying the compiler to be gcc-14 instead of gcc for the programs you want to compile.

I did build a cross-compiler once. It kept crashing my system during the build.

Your system crashing when you tried to build a bleeding-edge compiler from source has nothing to do with the distro being incompatible with that compiler. It honestly sounds like a hardware stability issue!

It's a pretty normal thing to compile a modern compiler on an older platform โ€“ after all, someone has to do that to develop that newer compiler, right?

In the case of GCC, it's (last time I checked) sufficient to specify a --prefix=/path/to/prefix --with-local-prefix=/path/to/prefix at the ./configure step, into which the newly compiled compiler suite would be installed when you make; sudo make install. Then, a simple export LD_LIBRARY_PATH=/path/to/prefix/lib64:${LD_LIBRARY_PATH} and export PATH=/path/to/prefix/bin:${PATH} is what it takes to then make use of this compiler.

Other than that, often you can just actually get the newer compilers packaged for your distro, either from additional package repositories, or through backporting them. gcc-15 is, unsurprisingly due to the lack of existence of the 15. release of GCC yet, not available on any Ubuntu version, but chances are not bad it would appear in the backports repository for the current Ubuntu LTS release, i.e., of Ubuntu 24.04.

2 of 2
2

Try rolling-release distros, they will most likely have the latest compiler versions when they release. A few that come to mind are Arch Linux, Void Linux and openSUSE Tumbleweed.