When gcc-11 will appear in Ubuntu repositories? [closed]

Posted on Jun 19, 2022

Question

GCC 11.1 was finally released yesterday. However, now it can only be built from source, so I'm wondering when we can get it with apt?

Answer

sudo apt install build-essential manpages-dev software-properties-common
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update && sudo apt install gcc-11 g++-11

Then use update-alternatives to set default gcc...

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-9 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-9  --slave /usr/bin/cpp cpp /usr/bin/cpp-9 && \

sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-11 110 –slave /usr/bin/g++ g++ /usr/bin/g++-11 –slave /usr/bin/gcov gcov /usr/bin/gcov-11 –slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-11 –slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-11 –slave /usr/bin/cpp cpp /usr/bin/cpp-11;

To sample check settings to see which gcc is default you can run the following, if they show correct resuslts then the rest are fine...

gcc --version;g++ --version;gcov --version;

To reconfigure to any previous gcc version...

sudo update-alternatives --config gcc

You can do this on any version of ubuntu,... enjoy!

Here are my 6 different gcc's living side by side with the default being gcc-11:

$ sudo update-alternatives --config gcc
There are 6 choices for the alternative gcc (providing /usr/bin/gcc).

Selection Path Priority Status

  • 0 /usr/bin/gcc-11 1010 auto mode 1 /usr/bin/gcc-10 1000 manual mode 2 /usr/bin/gcc-11 1010 manual mode 3 /usr/bin/gcc-5 40 manual mode 4 /usr/bin/gcc-7 700 manual mode 5 /usr/bin/gcc-8 800 manual mode 6 /usr/bin/gcc-9 900 manual mode

Press <enter> to keep the current choice[*], or type selection number: