First erase the current update-alternatives setup for gcc and g++:

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++

Install Packages

It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:

sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4

Install Alternatives

Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively. (Note that the 10, 20 and 30 options are the priorities for each alternative, where a bigger number is a higher priority.)

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

Configure Alternatives

The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Or switch using script:

#!/bin/sh

if [ -z "$1" ]; then
    echo "usage: $0 version" 1>&2
    exit 1
fi

if [ ! -f "/usr/bin/gcc-1" ]; then
    echo "no such version gcc/g++ installed" 1>&2
    exit 1
fi

update-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"
Answer from hhlp on askubuntu.com
Top answer
1 of 10
411

First erase the current update-alternatives setup for gcc and g++:

sudo update-alternatives --remove-all gcc 
sudo update-alternatives --remove-all g++

Install Packages

It seems that both gcc-4.3 and gcc-4.4 are installed after install build-essential. However, we can explicitly install the following packages:

sudo apt-get install gcc-4.3 gcc-4.4 g++-4.3 g++-4.4

Install Alternatives

Symbolic links cc and c++ are installed by default. We will install symbol links for gcc and g++, then link cc and c++ to gcc and g++ respectively. (Note that the 10, 20 and 30 options are the priorities for each alternative, where a bigger number is a higher priority.)

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20

sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
sudo update-alternatives --set cc /usr/bin/gcc

sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
sudo update-alternatives --set c++ /usr/bin/g++

Configure Alternatives

The last step is configuring the default commands for gcc, g++. It's easy to switch between 4.3 and 4.4 interactively:

sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Or switch using script:

#!/bin/sh

if [ -z "$1" ]; then
    echo "usage: $0 version" 1>&2
    exit 1
fi

if [ ! -f "/usr/bin/gcc-1" ]; then
    echo "no such version gcc/g++ installed" 1>&2
    exit 1
fi

update-alternatives --set gcc "/usr/bin/gcc-$1"
update-alternatives --set g++ "/usr/bin/g++-$1"
2 of 10
62

execute in terminal :

gcc -v
g++ -v

Okay, so that part is fairly simple. The tricky part is that when you issue the command GCC it is actually a sybolic link to which ever version of GCC you are using. What this means is we can create a symbolic link from GCC to whichever version of GCC we want.

  • You can see the symbolic link :
ls -la /usr/bin | grep gcc-4.4
ls -la /usr/bin | grep g++-4.4
  • So what we need to do is remove the GCC symlink and the G++ symlink and then recreate them linked to GCC 4.3 and G++ 4.3:
rm /usr/bin/gcc
rm /usr/bin/g++

ln -s /usr/bin/gcc-4.3 /usr/bin/gcc
ln -s /usr/bin/g++-4.3 /usr/bin/g++
  • Now if we check the symbolic links again we will see GCC & G++ are now linked to GCC 4.3 and G++ 4.3:
ls -la /usr/bin/ | grep gcc
ls -la /usr/bin/ | grep g++
  • Finally we can check our GCC -v again and make sure we are using the correct version:
gcc -v
g++ -v
🌐
GitHub
gist.github.com › cobaohieu › ded429cb892b46ae9bfd9919a11e593a
update-alternatives for gcc on Ubuntu - Gist - GitHub
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11 $ sudo update-alternatives --config gcc There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
Discussions

Upgrade broke my system
So it seems that gcc-11 was my default compiler despite gcc-12 already installed. I went ahead and installed g++-12. Then i changed the default compiler with update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100 update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 50 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 50 update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-12 100 update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-12 50 update-alternatives --set g++ /usr/bin/g++-12 update-alternatives --set gcc /usr/bin/gcc-12 update-alternatives --set cpp-bin /usr/bin/cpp-12 And then installing nvidia drivers worked without errors ngl though its pretty stupid that linux systems still break till this day because of an upgrade No wonder people still use windows and macos pft More on reddit.com
🌐 r/pop_os
10
3
March 14, 2023
How to use a newer version of gcc on ubuntu? - Stack Overflow
I am running ubuntu 18.04 and I currently have: (tensorflow_p36) ubuntu@user:~$ gcc --version gcc (GCC) 4.8.5 (tensorflow_p36) ubuntu@user:~$ gcc-8 --version gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1)... More on stackoverflow.com
🌐 stackoverflow.com
linux - How to change the default GCC compiler in Ubuntu? - Stack Overflow
VER=4.6 ; PRIO=60 sudo ... sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-$VER $PRIO --slave /usr/bin/g++ g++ /usr/bin/g++-$VER ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Oh the places you’ll go with spatial... The 2026 Developer Survey is now open (for human developers... ... 2 cc1plus: error: unrecognized command line option ‘-std=c++11’ while installing Cling in Ubuntu 12.04 using ... More on stackoverflow.com
🌐 stackoverflow.com
How to switch from gcc9 to gcc10 - g++9 to g++10
Hi! I can't switch from gcc9 to gcc10 / g++9 to g++10 I installed all needed gcc10/g++10 packages. When I run this commands: sudo update-alternatives --config gcc sudo update-alternatives --config g++ error: update-alternatives: error: no alternatives for gcc update-alternatives: error: no ... More on ubuntu-mate.community
🌐 ubuntu-mate.community
1
0
May 13, 2021
🌐
GitHub
gist.github.com › yunqu › 0cc6347905f73b7448898f50484e77b3
Install a different version of GCC on Ubuntu · GitHub
Later if you want to change the default version use the update-alternatives command: ... There are 3 choices for the alternative gcc (providing /usr/bin/gcc).
🌐
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 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 --slave /usr/bin/g++ g++ /usr/bin/g++-12
🌐
FOSS Linux
fosslinux.com › home › programming › how to install and switch gcc versions on ubuntu: the 2026 master guide
How to Install and Switch GCC Versions on Ubuntu: The 2026 Master Guide
April 21, 2026 - # Registering GCC versions with specific priorities fosslinux@tuts:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 fosslinux@tuts:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12 fosslinux@tuts:~$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 # Mirroring the registration for G++ (Mandatory Sync) fosslinux@tuts:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11 fosslinux@tuts:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 12 fosslinux@tuts:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-13 13
🌐
LinuxConfig
linuxconfig.org › home › how to switch between multiple gcc and g++ compiler versions on ubuntu 20.04 lts focal fossa
How to switch between multiple GCC and G++ compiler versions on Ubuntu 20.04 LTS Focal Fossa
September 21, 2025 - Selection Path Priority Status ... /usr/bin/gcc-9 9 manual mode Press · to keep the current choice[*], or type selection number: ... $ sudo update-alternatives --config g++ There are 3 choices for the alternative g++ (providing /usr/bin/g++)....
🌐
Reddit
reddit.com › r/pop_os › upgrade broke my system
r/pop_os on Reddit: Upgrade broke my system
March 14, 2023 -

im not tech savvy so please be patient with me:). So a sudo apt upgrade broke my system, specifically i could not use nvidia drivers anymore. Searching here and there I did sudo apt purge *nvidia* and tried installing the older nvidia driver again but same error happens as when I tried upgrading .

Errors were encountered while processing:  nvidia-dkms-470  nvidia-driver-470 E: Sub-process /usr/bin/dpkg returned an error code (1) 

So the make log file in /var/lib/dkms/nvidia/470.63.01/build/make.log showed:

warning: the compiler differs from the one used to build the kernel
  The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0
  You are using:           cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

gcc-12 is already installed, I dont know what i am doing wrong ? :(

Top answer
1 of 5
5
So it seems that gcc-11 was my default compiler despite gcc-12 already installed. I went ahead and installed g++-12. Then i changed the default compiler with update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100 update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 50 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 50 update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-12 100 update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-12 50 update-alternatives --set g++ /usr/bin/g++-12 update-alternatives --set gcc /usr/bin/gcc-12 update-alternatives --set cpp-bin /usr/bin/cpp-12 And then installing nvidia drivers worked without errors ngl though its pretty stupid that linux systems still break till this day because of an upgrade No wonder people still use windows and macos pft
2 of 5
2
Run the following command to fix any broken dependencies, and complete any pending installation or removal process: sudo apt-get install -f If it doesn't work you can remove the partially installed packages using the command: sudo dpkg --remove --force-all nvidia-dkms-470 nvidia-driver-470 I recommend installing the Nvidia driver suggested by your system by running the following commands: sudo apt-get update sudo apt-get install nvidia-detect sudo nvidia-detect Install the driver using the following command: sudo apt-get install nvidia-driver-xxx You will have to reboot your device, then use the command: nvidia-smi This will display information about your current driver and the GPU. If it gives an error the GPU is either not detected or the driver wasn't installed properly. Hope it helps!
Top answer
1 of 2
2

It's possible you arrived because something blew up with nvidia. (I'm on cudatoolkit 11.4 and actually downgrading got me out of trouble - your mileage may vary.)

sudo apt install gcc-9 g++-9
sudo mkdir /usr/local/cuda/bin
sudo ln -s /usr/bin/gcc-9 /usr/local/cuda/bin/gcc

WARNING - I recommend using timeshift to make a backup of your working system. https://github.com/teejee2008/timeshift

This will get you the latest gcc 11

sudo add-apt-repository 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
sudo apt-get install g++-11
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 50
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 50
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 100
sudo update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-11 50
sudo update-alternatives --set g++ /usr/bin/g++-11
sudo update-alternatives --set gcc /usr/bin/gcc-11
sudo update-alternatives --set cpp-bin /usr/bin/cpp-11
gcc --version
gcc (Ubuntu 11-20210417-1ubuntu1) 11.0.1 20210417 

Copyright (C) 2021 Free Software Foundation, Inc.

2 of 2
0

From the looks of it, inside your conda environment, the gcc command has been linked to /home/ubuntu/anaconda3/envs/tensorflow_p36/bin/gcc, and the version is 4. Whereas outside the environment, the only gcc on the path is gcc-8, which corresponds to version 8.

Also, as you've observed, you are unable to create an alternative for gcc because it is linked to g++ alternative.

I also prefer to have gcc be the main alternative, and all other tools (including g++) follow suit. In this case, I will start by deleting the g++ alternative:

sudo update-alternatives --remove-all g++

Now that we've got that out of the way, we can create one for gcc which links to gcc-8

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-8 --slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-8 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-8

References

  1. https://askubuntu.com/a/26518/145907
  2. https://askubuntu.com/a/1206264/145907
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
April 30, 2026 - If the error names a specific branch, such as /bin/sh: 1: gcc-12: not found, install that matching versioned package instead. Install build-essential to get the default compiler with all standard symlinks: ... sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 140 \ --slave /usr/bin/g++ g++ /usr/bin/g++-14
Top answer
1 of 9
147

As @Tommy suggested, you should use update-alternatives.
It assigns values to every software of a family, so that it defines the order in which the applications will be called.

It is used to maintain different versions of the same software on a system. In your case, you will be able to use several declinations of gcc, and one will be favoured.

To figure out the current priorities of gcc, type in the command pointed out by @tripleee's comment:

update-alternatives --query gcc

Now, note the priority attributed to gcc-4.4 because you'll need to give a higher one to gcc-3.3.
To set your alternatives, you should have something like this (assuming your gcc installation is located at /usr/bin/gcc-3.3, and gcc-4.4's priority is less than 50):

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.3 50

--edit--

Finally, you can also use the interactive interface of update-alternatives to easily switch between versions. Type update-alternatives --config gcc to be asked to choose the gcc version you want to use among those installed.

--edit 2 --

Now, to fix the CXX environment variable systemwide, you need to put the line indicated by @DipSwitch's in your .bashrc file (this will apply the change only for your user, which is safer in my opinion):

echo 'export CXX=/usr/bin/gcc-3.3' >> ~/.bashrc
2 of 9
82

Here's a complete example of jHackTheRipper's answer for the TL;DR crowd. :-) In this case, I wanted to run g++-4.5 on an Ubuntu system that defaults to 4.6. As root:

apt-get install g++-4.5
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.5 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.5 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.5 50
update-alternatives --set g++ /usr/bin/g++-4.5
update-alternatives --set gcc /usr/bin/gcc-4.5
update-alternatives --set cpp-bin /usr/bin/cpp-4.5

Here, 4.6 is still the default (aka "auto mode"), but I explicitly switch to 4.5 temporarily (manual mode). To go back to 4.6:

update-alternatives --auto g++
update-alternatives --auto gcc
update-alternatives --auto cpp-bin

(Note the use of cpp-bin instead of just cpp. Ubuntu already has a cpp alternative with a master link of /lib/cpp. Renaming that link would remove the /lib/cpp link, which could break scripts.)

🌐
GitHub
gist.github.com › application2000 › 73fd6f4bf1be6600a2cf9f56315a2d91
How to install latest gcc on Ubuntu LTS (12.04, 14.04, 16.04) · GitHub
sudo apt-get update -y && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo apt-get install build-essential software-properties-common -y && sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && sudo apt-get update -y && sudo apt-get install gcc-9 g++-9 -y && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-9 && sudo update-alternatives --config gcc
🌐
Digipen
azrael.digipen.edu › ~mmead › www › mg › update-compilers › index.html
Mead's Guide to Upgrading GCC and Clang on Linux
November 16, 2021 - But, they are in place so that when you decide to have multiple versions/programs for one command, you can do so easily. Let's look at gcc: ... update-alternatives: error: no alternatives for gcc This is telling us that there currently is no alternative for gcc.
🌐
GitHub
gist.github.com › Aleksoid1978 › ef09c680b82d2032fd78c7c51d3b36e9
update-alternatives for gcc on Ubuntu · GitHub
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7 --slave /usr/bin/g++ g++ /usr/bin/g++-7 --slave /usr/bin/gcov gcov /usr/bin/gcov-7 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8 --slave /usr/bin/g++ g++ /usr/bin/g++-8 --slave /usr/bin/gcov gcov /usr/bin/gcov-8 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10 $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11 $ sudo update-alternatives --config gcc There are 2 choices for the alternative gcc (providing /usr/bin/gcc).
🌐
Stack Overflow
stackoverflow.com › questions › 77189502 › how-can-i-replace-gcc-with-g-11-for-c20-when-running-cmake
network programming - How can I replace gcc with g++-11 for C++20 when running cmake - Stack Overflow
thank you for updating the answers. now that i think about it it's much clearer. i use the following to set priorities now:sudo update-alternatives --config gcc/++, sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10, sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 20, sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 10, sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 20,sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30, sudo update-alternatives --set cc /usr/bin/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.

🌐
Logikal Blog
logikalsolutions.com › home › changing default compiler on opensuse
Changing Default Compiler on OpenSuSE - Logikal Solutions
June 30, 2024 - Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/gcc-11 50 auto mode 1 /usr/bin/gcc-11 50 manual mode 2 /usr/bin/gcc-7 20 manual mode Press <enter> to keep the current choice[*], or type selection number: localhost:~ # update-alternatives --config cpp There are 2 choices for the alternative cpp (providing /usr/bin/cpp).
🌐
The Fedora Project
fedoraproject.org › wiki › Changes › Use-Update-Alternatives-For-usr-bin-cc
Changes/Use-Update-Alternatives-For-usr-bin-cc - Fedora Project Wiki
February 11, 2021 - The clang package currently has ... way users will be able to change the /usr/bin/cc or /usr/bin/c++ implementations will be by explicitly using the update-alternatives tool....
🌐
openSUSE
en.opensuse.org › User:Tsu2 › gcc_update-alternatives
User:Tsu2/gcc update-alternatives - openSUSE Wiki
October 2, 2016 - If you want the additional gcc options, go ahead and create more based on the following two commands which can be run individually or placed in a script. Note that whatever you configure first will be the default(although you can change later if you make this minor mistake) update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 50 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20
🌐
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 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 14 --slave /usr/bin/g++ g++ /usr/bin/g++-14