6

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.

Regards

BobMorane
  • 197

2 Answers2

4

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

or

make CC=/usr/bin/gcc-7

or

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

-- see for example CMake Useful Variables.

steeldriver
  • 136,215
  • 21
  • 243
  • 336
4

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

RUN \
  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