7

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 

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 
4
  • 1
    You need to set a specific gcc executable as an alternative to gcc and a specific g++ executable as an alternative to g++, never mix them and do not use --slave. Use two separate update-alternatives commands, one for gcc and one for g++. Commented Nov 23, 2019 at 17:58
  • Thank you for pointing me in the right direction. Updated my question Commented Nov 23, 2019 at 19:53
  • 1
    You are using the gcc provided by anaconda, not the one installed from the ubuntu repositories. As you are saying the problem is not presents outside the conda environment. So I guess you should be asking how to upgrade to a newer gcc version in anaconda. Commented Nov 23, 2019 at 20:13
  • You're right, I asked here: stackoverflow.com/questions/59015125/…. Completely stuck on this issue. Commented Nov 24, 2019 at 6:17

2 Answers 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.

Sign up to request clarification or add additional context in comments.

2 Comments

When setting the gcc version alternative to contain 11, shouldent the first command contain the old version? eg. 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 to sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 50
This is also a useful reference: askubuntu.com/questions/26498/…
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.