greenberet123
greenberet123

Reputation: 1477

Update gcc alternatives in Ubuntu 18.04 - g++ cannot be slave of gcc

Trying to update alternatives but get this error. Googling doesn't show up any solutions.

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

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

Upvotes: 6

Views: 6884

Answers (1)

FranzBranntwein
FranzBranntwein

Reputation: 361

This seems to be intended behaviour, but may differ in some releases of Ubuntu. So in order to avoid that issue for g++:

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

simply call it up individually in update-alternatives, e.g.:

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 110

Be aware to have this maybe in sync with the other GNU tools.

It seems not to be an issue in Ubuntu 20.04 LTS for g++, but for cpp nevertheless, so in order to avoid that issue for cpp there:

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

for instance in the case of upgrading from gcc-9 to gcc-11 and to keep the other alternatives in sync, the following worked under Ubuntu 20.04 LTS:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update && sudo apt-get install gcc-11 g++-11 cpp-11
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 && \
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-9 90
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 && \
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-11 110

Validation might be done via:

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

Edit:

For the interested, upgrading the gdb in this context has the following steps:

gdbVersion=11.1
wget http://ftp.gnu.org/gnu/gdb/gdb-${gdbVersion}.tar.xz
tar -xf gdb-${gdbVersion}.tar.xz
cd gdb-${gdbVersion}/
./configure
make
sudo make install

Validation:

gdb --version

Upvotes: 11

Related Questions