I want to install the latest gcc package (7.1) on Xubuntu 16.04.4. I have successfully installed the package following the instructions given here from GAD3R.

The problem is that when I run:

gcc --version

I get the following output:

gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

which means that my OS doesn't see the newly installed gcc as the default compiler. How can I achieve that?

Furthermore, I you have a more trusty source than the one presented in the link, please feel free to add it.


2 Answers 2


AFAIK the toochain-r PPA that you used is the recommended source for alternate versions of GCC. To make it the default, you can either use the update-alternatives mechanism as explained in this previous Q&A

How to use multiple instances of gcc?

or by direct symlinking as described in

Downloaded g++ 4.8 from the PPA but can't set it as default?

Although in practice it's often not necessary, since most build systems allow you to specify a particular compiler, either using command-line arguments or environment variables e.g.

CC=/usr/bin/gcc-7 ./configure


make CC=/usr/bin/gcc-7


cmake -D CMAKE_C_COMPILER=/usr/bin/gcc-7 ..

-- see for example CMake Useful Variables.

  • Great answer. Specifying the right gcc to cmake worked fine. Thank you! Feb 27, 2019 at 22:23

You can use update-alternatives to make it default:

update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 60

For instance, this Dockerfile gives you Ubuntu 16.04 with gcc 7:

FROM ubuntu:16.04

  apt-get update && \
  apt-get install -y software-properties-common && \
  add-apt-repository ppa:ubuntu-toolchain-r/test && \
  apt-get update && \
  apt-get install -y gcc-7 g++-7 && \
  update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 60 && \
  update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60
CMD /bin/bash
  • Thanks a lot. could you please also explain what that 60 is for at the end?
    – Hossein
    Jul 19, 2021 at 7:06
  • 1
    @Rika You need to specify a priority. In this example, using different values should not matter, so 60 is rather arbitrary. There is a related question about priorities: askubuntu.com/q/533391/117753 Jul 19, 2021 at 8:13
  • Thanks a lot really appreciate it
    – Hossein
    Jul 19, 2021 at 8:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .