3

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) 8.3.0

(tensorflow_p36) ubuntu@user:~$ which gcc
/home/ubuntu/anaconda3/envs/tensorflow_p36/bin/gcc

I am trying to use the latest gcc-8 as show here. However when I run

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8

I get the following error:

update-alternatives: error: alternative g++ can't be slave of gcc: it is a master alternative

When I try:

(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --config gcc

I get another error:

update-alternatives: error: no alternatives for gcc

How is it that I do not have alternative for gcc? Any suggestions on how I can resolve this error and configure gcc-8 to be the default gcc installation would be appreciated.


Running which gcc from outside the conda environment does not return anything:

ubuntu@user:~$ which gcc
ubuntu@user:~$

but

ubuntu@user:~$ gcc-8 --version
gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0

I tried following the question here:

(tensorflow_p36) ubuntu@user:~$ sudo apt install g++-8
g++-8 is already the newest version (8.3.0-6ubuntu1~18.04.1).

and

(tensorflow_p36) ubuntu@user:~$ sudo apt install gcc-8
gcc-8 is already the newest version (8.3.0-6ubuntu1~18.04.1).

Update. I'm trying the following as per the helpful suggestion below, but still to no avail.

(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 40
(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 60
(tensorflow_p36) ubuntu@user:~$ sudo update-alternatives --config g++
There are 3 choices for the alternative g++ (providing /usr/bin/g++).

  Selection    Path                             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/x86_64-linux-gnu-g++-7   100       auto mode
  1            /usr/bin/g++-4.8                  60        manual mode
  2            /usr/bin/g++-8                    40        manual mode
  3            /usr/bin/x86_64-linux-gnu-g++-7   100       manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/g++-8 to provide /usr/bin/g++ (g++) in manual mode

So far so good, but when I test the g++ version, it's still the same!

~$ g++ --version
g++ (GCC) 4.8.5

EDIT

I also try with gcc:

There are 2 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-8     80        auto mode
  1            /usr/bin/gcc-4.8   60        manual mode
* 2            /usr/bin/gcc-8     80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 0
(tensorflow_p36) ubuntu@user:~$ gcc --version
gcc (GCC) 4.8.5
rrz0
  • 161
  • 2
  • 7
  • Seems like expected behavior. Your gcc is not in any of the usual locations that a deb package would put it. It's in some weird anaconda-based location, which means it's likely not a deb package. Maybe it's a pip or something else? `update-alternatives` only works with deb packages. – user535733 Nov 23 '19 at 17:43
  • Could be a pip. Im using an aws pre-configured `ec2` instance so that night be why. – rrz0 Nov 23 '19 at 17:51
  • Possible duplicate of [How can I force an older version of g++ if I have a newer version?](https://askubuntu.com/questions/1188341/how-can-i-force-an-older-version-of-g-if-i-have-a-newer-version) – karel Nov 23 '19 at 17:55
  • Thanks for pointing me in the right direction. I'm not sure how to proceed with the second step given that I am trying to upgrade an d not downgrade. – rrz0 Nov 23 '19 at 19:44
  • If you need it temporarily I'd recommend setting an alias in your shell's configuration file. Read more [here](https://askubuntu.com/a/17538/787213). – Manas Singh Nov 23 '19 at 20:35
  • The default version of gcc is the version with the highest priority. – karel Nov 23 '19 at 20:45

0 Answers0