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
🌐
GNU
gcc.gnu.org › install
Installing GCC - GNU Project
The latest version of this document is always available at https://gcc.gnu.org/install/. It refers to the current development sources, instructions for specific released versions are included with the sources.
🌐
Medium
medium.com › @darrenjs › building-gcc-from-source-dcc368a3bb70
Building GCC from source. Step by step guide on building GCC 9 | by Darren Smith | Medium
June 2, 2019 - GCC is open source software, so you can download the source code, configure & build, and install into a directory of your choice. No financial cost; no root permissions or privileges required; you can choose the compiler options most suitable ...
🌐
Sorush Khajepor
iamsorush.com › posts › build-gcc11
Build GCC 11 from source on Ubuntu
Instead of editing ~/.bashrc, another option is to create a file like ~/load_gcc11.1.sh and paste the above export lines in it. Then whenever you need to load this GCC in a terminal, you run ... In this way, you can have multiple versions, and load the one that suits your project. ... The default installation of GCC on Ubuntu is accessible with commands without the version extension:
🌐
GitHub
gist.github.com › dstrebkov › ebe070c1e35d94f859c6cacae8d642ef
GCC 12 or GCC 13 install from sources · GitHub
GCC 12 or GCC 13 install from sources. GitHub Gist: instantly share code, notes, and snippets.
🌐
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 - sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y · 3. Use the wget command to download the GCC source code from the GCC website.
🌐
FlamingBytes
flamingbytes.com › blog › install-gcc-from-source
Install GCC from source | FlamingBytes
October 22, 2023 - $ cd gcc-12.2.0/ $ ./contrib/download_prerequisites 2023-02-01 00:41:01 URL:http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.2.1.tar.bz2 [2493916/2493916] -> "gmp-6.2.1.tar.bz2" [1] 2023-02-01 00:41:02 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-4.1.0.tar.bz2 [1747243/1747243] -> "mpfr-4.1.0.tar.bz2" [1] 2023-02-01 00:41:03 URL:http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.2.1.tar.gz [838731/838731] -> "mpc-1.2.1.tar.gz" [1] 2023-02-01 00:41:04 URL:http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.24.tar.bz2 [2261594/2261594] -> "isl-0.24.tar.bz2" [1] gmp-6.2.1.tar.bz2: OK mpfr-4.1.0.tar.bz2: OK mpc-1.2.1.tar.gz: OK isl-0.24.tar.bz2: OK All prerequisites downloaded successfully.
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.

🌐
Inl
mooseframework.inl.gov › getting_started › installation › manual_installation_gcc.html
GCC from Source | MOOSE
We need a modern C++17 capable compiler. Our minimum requirements are: GCC 9.0.0, Clang 14.0.6. This section will focus on building a GCC 13.3.1 compiler stack. Obtain GCC source: curl -L -O http://mirrors.concertpass.com/gcc/releases/gcc-13.3.1/gcc-13.3.1.tar.gz tar -xf gcc-13.3.1.tar.gz -C .
Find elsewhere
🌐
GitHub
gist.github.com › jeetsukumaran › 5224956
Build and Install GCC Suite from Scratch · GitHub
#! /bin/bash GCC_VERSION="9.3.0" WORKDIR="$HOME/src/" INSTALLDIR="/platform" ## NOTE: XCode must be installed (through App Store) and the following run to install command-line tools. ## THIS IS IMPORTANT! Among other things, it creates '/usr/include' and installs the system header files. # xcode-select --install # get the source code cd $WORKDIR wget http://www.netgull.com/gcc/releases/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.gz tar -xvf gcc-${GCC_VERSION}.tar.gz # download the prerequisites cd gcc-${GCC_VERSION} ./contrib/download_prerequisites # create the build directory cd ..
🌐
GitHub
gist.github.com › yosoufe › ad45f45c10fe08abecbf53000d0d199f
Compile and install gcc-9.3.0 · GitHub
# requirements sudo apt-get install flex bison mkdir build ./contrib/download_prerequisites --directory=build cd build ../configure \ --prefix=/usr \ --disable-multilib \ --with-system-zlib \ --enable-languages=c,c++,d,fortran,go,objc,obj-c++ \ --program-suffix=-9.3.0 make -j$(nproc) sudo make install -j$(nproc) ... Hi @yosoufe, thanks for this is helped me a lot. Just a small issue. contrib/download_prerequisites wants to be run from the directory where contrib lives, so the commands are like this": ./contrib/download_prerequisites mkdir build cd build ../configure ... ... Thanks @MikeOpenHWGroup, I retested and updated the gist. ... @yosoufe VMware needs to know where the directory for 9.3.0 (gcc) is so it can be installed.
🌐
OpenGenus
iq.opengenus.org › build-gcc-from-source
Build GCC from source [GCC v12.2.0]
October 17, 2022 - To build GCC from source after configuration, use the following command: ... git clone https://github.com/gcc-mirror/gcc.git cd gcc git checkout releases/gcc-12.2.0 ./contrib/download_prerequisites cd .. mkdir objdir cd objdir $PWD/../gcc-12.2.0/configure --prefix=$HOME/GCC-12.2.0 ...
🌐
GNU
gcc.gnu.org › install › build.html
Installing GCC: Building - GNU Project
Build runtime libraries using the compiler from the previous step. Note that if an error occurs in any step the make process will exit. If you are not building GNU Binutils in the same source tree as GCC, you will need a cross-assembler and cross-linker installed before configuring GCC.
🌐
GNU
gcc.gnu.org › install › download.html
Downloading GCC - GNU Project
Please refer to the releases web page for information on how to obtain GCC. The source distribution includes the Ada, C, C++, Objective-C, COBOL (GCC 15 and later), D (GCC 9 and later), Fortran, Go, Modula-2 (GCC 13 and later) and Algol 68 (GCC 16 and later, experimental) compilers, as well as runtime libraries for C++, Objective-C, COBOL, Fortran and Algol 68.
🌐
JWillikers
jwillikers.com › build-gcc-from-source-on-centos-7
Build GCC From Source on CentOS 7 - JWillikers
October 28, 2020 - Otherwise, the signature is bad and you must re-download the source archive. Extract the archive. ... Make a build directory. ... Change into the build directory. ... Run the configure script to prepare the build. ../gcc-10.2.0/configure --enable-languages=c,c++,fortran \ --disable-multilib --prefix=$HOME/.gcc/10.2.0 ... Wait patiently for GCC to finish compiling itself. Install GCC.
🌐
D-meiser
d-meiser.github.io › 2015 › 11 › 30 › building-gcc-trunk.html
Building gcc from source
Depending on the install prefix you may need super user privileges for this step. To use the new compiler and to run the programs generated with it you’ll have to make sure that it’s libraries can be found. The easiest way to do that is by adding /usr/gcc-trunk/lib64 to the LD_LIBRARY_PATH environment variable:
🌐
iO Flood
ioflood.com › blog › install-gcc-command-linux
Installing and Using the GCC Command: Linux User Guide
January 2, 2024 - This will download the GCC 9.2.0 source code, configure the build, and then compile and install GCC. The --disable-multilib flag is used to only support 64-bit software, and --enable-languages=c,c++ is used to only build the C and C++ compilers. Different versions of GCC have different features and support for different language standards. You might need a specific version of GCC for a certain codebase. Here’s how you can install different versions of GCC from source and using package managers.
🌐
Reddit
reddit.com › r/gcc › recommendation(s) for building gcc on linux box
r/gcc on Reddit: Recommendation(s) for Building GCC on Linux box
October 28, 2023 -

I'm running antiX Linux on a 64-bit ASUS laptop

I need the latest & greatest version of `gcc’ in order to compile from source the latest & greatest Gambit-C Scheme compiler.

got gcc cloned from github!

Got objdir directory made in top of source tree.
cd objdir
../configure [options ???] [target ????]

I need advise for the options & target please.

for “target” is –host=x86_64-pc-linux-gnu ok?

for “options”. I have zero clue!!
TIA …

🌐
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 - Run the Command below to Install the required Dependencies: ... Download the GCC source code from the GCC website using the wget command.