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
🌐
Linux Hint
linuxhint.com › install-gcc-ubuntu22-04
How to install GCC on Ubuntu 22.04 – Linux Hint
To install GCC, first update the system then install the build-essential package that contains the GCC package using “$ sudo apt install build-essential” command.
🌐
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 - 2. Install the libgmp3-dev, libmpfr-dev, and libmpc-dev packages to facilitate compiling GCC from source: sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
Discussions

Ubuntu 18.10 - how to install a specific version of gcc - Stack Overflow
I wanted to install gcc-6 alongside my existing installation of gcc-9 and this is how I did it. First off, sudo apt install gcc-6 didn't work because the package wasn't found so I had to add a new repository that contained gcc-6. More on stackoverflow.com
🌐 stackoverflow.com
linux - how to install gcc-12 on ubuntu - Stack Overflow
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 ... More on stackoverflow.com
🌐 stackoverflow.com
apt - Install GCC 7 on Ubuntu? - Unix & Linux Stack Exchange
Command is now sudo add-apt-repository ppa:jonathonf/gcc, without the trailing -7. You can also get other GCC versions from the repo. Don't forget the apt update! ... If you need to setup a test rig with the compiler, then Fedora 26 ships with GCC 7.1. You can also find GCC 7 in Debian 10/Buster (Debian 9 with Testing repo enabled). For Debian, you must apt-get install ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
Installing gcc-10 on Debian Buster
The package is there at http://ftp.cz.debian.org/debian/pool/main/g/gcc-10/ . This doesn't mean it's installable on buster. The pool is shared by all distros present on a mirror. I added the following line to the /etc/apt/sources.list file: deb http://ftp.cz.debian.org/debian buster main You don't need to add a second buster mirror. All of them are the same. Is there anything I am missing or doing wrong? gcc-10 is not available for buster. You may be interested in https://www.reddit.com/r/debian/comments/mmure2/upgrading_the_gcc_gnu_compiler_in_buster/ More on reddit.com
🌐 r/debian
3
3
April 14, 2021
🌐
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 - Perform the steps below to install the GCC Compiler Ubuntu 18.04: Start by updating the packages list: Terminal · sudo apt update · Install the build-essential package by typing: Terminal · sudo apt install build-essential · The command ...
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.

🌐
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
1 week ago - Source builds take substantially longer than APT installs and require several gigabytes of temporary disk space. Reserve this method for scenarios where repository versions lack required features or when you need precise control over the compiler toolchain configuration. Install the prerequisite development tools and mathematical libraries GCC requires: sudo apt install build-essential flex bison libgmp3-dev libmpc-dev libmpfr-dev libisl-dev texinfo
Find elsewhere
🌐
CyberPanel
cyberpanel.net › blog › install-gcc-on-ubuntu
How To Install GCC On Ubuntu: Easiest Methods Explained!
February 2, 2026 - 2. Next, install the libgmp3-dev, libmpfr-dev, and libmpc-dev packages to help compile GCC from source: sudo apt install libmpfr-dev libgmp3-dev libmpc-dev -y
🌐
Ubuntu
documentation.ubuntu.com › ubuntu-for-developers › howto › gcc-setup
How to set up a development environment for GCC on Ubuntu - Ubuntu for Developers
1 week ago - dev@ubuntu:~$ sudo apt install default-jre > sudo snap install netbeans --classic · From within NetBeans, install the C/C++ Pack by going to Tools ‣ Plugins ‣ Available Plugins ‣ Install. The standard debugger developed for GCC is the GNU Debugger (GDB).
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.

Top answer
1 of 3
7

To install gcc-7 on ubuntu you should use this ppa:

sudo add-apt-repository ppa:jonathonf/gcc
sudo apt-get update

Then run: apt-cache search gcc-7

sample output :

gcc-7-base - GCC, the GNU Compiler Collection (base package)
gcc-7 - GNU C compiler
gcc-7-multilib - GNU C compiler (multilib support)
gcc-7-plugin-dev - Files for GNU GCC plugin development.
gcc-7-test-results - Test results for the GCC test suite
lib32gcc-7-dev - GCC support library (32 bit development files)
libgcc-7-dev - GCC support library (development files)
gcc-7-doc - Documentation for the GNU compilers (gcc, gobjc, g++)
gcc-7-hppa64-linux-gnu - GNU C compiler (cross compiler for hppa64)
gcc-7-locales - GCC, the GNU compiler collection (native language support files)
gcc-7-source - Source of the GNU Compiler Collection
libx32gcc-7-dev - GCC support library (x32 development files)
gcc-7-offload-nvptx - GCC offloading compiler to NVPTX
lib64gcc-7-dev - GCC support library (64bit development files)

Install gcc-7:

sudo apt install gcc-7
2 of 3
2

If you need to setup a test rig with the compiler, then Fedora 26 ships with GCC 7.1.

You can also find GCC 7 in Debian 10/Buster (Debian 9 with Testing repo enabled). For Debian, you must apt-get install gcc-7 g++-7.

For completeness, its not clear which version of the Microsoft compilers support C++17 and std::byte (the reason I needed the compiler for testing).

And thanks to GAD3R for his help. The reason I avoided it was I could not establish provenance for some of the PPAs.

🌐
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 ... command as root or user with sudo privileges : Terminal · sudo apt update sudo apt install build-essential ·...
🌐
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 - Installation of GCC can be achieved by using the apt install command as you will see below. ... Although you can install the C compiler separately by installation of the gcc package, the recommended way to install the C compiler on Ubuntu 22.04 ...
🌐
Namehero
namehero.com › blog › how-to-install-gcc-on-ubuntu
How To Install GCC On Ubuntu
November 4, 2024 - Enter the following command and press Enter: sudo apt update · Step 3: Install GCC · Now, it’s time to install GCC. Enter the following command and press Enter: sudo apt install gcc ·
🌐
Learn Ubuntu
learnubuntu.com › install-gcc
How to Install GCC on Ubuntu
December 5, 2022 - I assume you want to install GCC because you are working on a software project written in the C programming language. In that case, I advise you to install the build-essential pacakge. It is a meta package of sorts. A meta package is a package that does not have anything of its own but rather acts as a package to install a collection of related packages. The build-essential meta package can be easily installed with the apt package manager:
🌐
LinuxTect
linuxtect.com › how-to-install-gcc-compiler-on-ubuntu
How To Install GCC Compiler On Ubuntu? – LinuxTect
We can install the GCC with the following apt command for Ubuntu, Debian, Mint etc. We also provide the sudo command for root privileges.
🌐
iO Flood
ioflood.com › blog › install-gcc-command-linux
Installing and Using the GCC Command: Linux User Guide
January 2, 2024 - On Debian-based distributions, you can install a specific GCC version with the apt package manager: sudo apt install gcc-8 # Output: # 'Reading package lists... Done' # 'Building dependency tree' # 'Reading state information...
🌐
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 - To update the package list, use the following command: sudo apt update · We now install GCC with the following command. sudo apt install gcc · If GCC is already installed on your system, the command will list the version installed.
🌐
GitHub
gist.github.com › jlblancoc › 99521194aba975286c80f93e47966dc5
Installing gcc-7 & g++-7 in Ubuntu 16.04LTS Xenial · GitHub
sudo apt-get install -y software-properties-common sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt update sudo apt install g++-7 -y · Set it up so the symbolic links gcc, g++ point to the newer version: