How to use update-alternatives in centos?

Viewed 4143

I'm trying to update GCC on centos 6.0 (for a manylinux pip wheel on docker). As later versions of gcc are not available for download I've built gcc-10.2 myself. I'm now trying to update centos to use the new gcc/g++ programs instead of the old ones. On ubuntu the command to do this is

update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10

and it appears that centos also has a similar tool. However, despite reading the documentation I cannot get the command (of a couple of variations) to work. Here is the command I'm running:

[root@aa5149016e33 /]# update-alternatives --install /usr/bin/g++ g++ gcc-10.2-centos/bin/g++
alternatives version 1.3.49.5 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: alternatives --install <link> <name> <path> <priority>
                    [--initscript <service>]
                    [--slave <link> <name> <path>]*
       alternatives --remove <name> <path>
       alternatives --auto <name>
       alternatives --config <name>
       alternatives --display <name>
       alternatives --set <name> <path>

common options: --verbose --test --help --usage --version
                --altdir <directory> --admindir <directory>
[root@aa5149016e33 /]#

How can I update centos so that the commands

gcc --version

and

g++ --version

refer to gcc 10.2?

Note also, I'm working from the root directory

[root@aa5149016e33 /]# tree -L 1 .
.
├── bin
├── boot
├── cgroup
├── dev
├── etc
├── gcc-10.2-centos
├── gcc-10.2-centos.zip
├── home
├── lib
├── lib64
├── lost+found
├── media
├── mnt
├── opt
├── proc
├── root
├── sbin
├── selinux
├── srv
├── sys
├── tmp
├── usr
└── var

and

[root@aa5149016e33 /]# tree -L 1 gcc-10.2-centos/bin/
gcc-10.2-centos/bin/
├── c++
├── cpp
├── g++
├── gcc
├── gcc-ar
├── gcc-nm
├── gcc-ranlib
├── gcov
├── gcov-dump
├── gcov-tool
├── lto-dump
├── x86_64-pc-linux-gnu-c++
├── x86_64-pc-linux-gnu-g++
├── x86_64-pc-linux-gnu-gcc
├── x86_64-pc-linux-gnu-gcc-10.2.0
├── x86_64-pc-linux-gnu-gcc-ar
├── x86_64-pc-linux-gnu-gcc-nm
└── x86_64-pc-linux-gnu-gcc-ranlib

0 directories, 18 files
1 Answers

Fedora/CentOS does not use alternatives to select the compiler. It is true that Fedora/CentOS has and uses the alternatives package. However alternatives does not automatically manage every installed software application, and each software package has to be explicitly set up to use alternatives, and in Fedora/CentOS this is simply not done for gcc.

Building gcc is no small feat. By comparison, using an explicit path to your custom gcc build seems like an insignificant triviality. Or, put your custom built gcc's location in your PATH environment variable first, and move on to something else.

Related