Complete set (I hope) of update-alternatives
commands for gcc
with slave entries for cpp
, g++
, gcc-ar
, gcc-nm
, gcc-ranlib
, gcov
, gcov-dump
, gcov-tool
, lto-dump
& matching x86_64-linux-gnu-
links!
Implemented / tested on Debian bookworm (testing)
Obviously, double-check before copy/pasting and hitting ⮐Enter
BACKGROUND
I'm not a programmer or coder or anything, but I do admin a number of Linux servers (CentOS and Debian) and run Debian testing at home. Usually I just apt install
something. Rarely do I have to ./configure && make && make install
so beyond that I don't have much knowledge. Before this, I only knew of gcc
and g++
, but have discovered at least 15 other links associated with the GNU Compiler Collection on my system, each pointing to a corresponding binary or other link.
Today, I have GCC 12 installed and trying to build something, but it's some older code so GCC 12 is too new. Time sure does fly, I remember when GCC 4 was common! When I checked, my system has versions 8, 9, 10, and 11 also. Yet when I updated GCC to point to the version 11 binaries, it didn't change anything. I realized gcc-11 wasn't even a binary anymore. It's a link now too, to x86_64-linux-gnu-gcc-11
which is the target binary. In fact, all of the binaries now start with a x86_64-linux-gnu-
and end with a -vers
and have a corresponding generic link starting with x86_64-linux-gnu-
.
I came up with this command then, to install the alternatives that can be switched with update-alternatives
command. Just replace the value of the vers
variable in the beginning to correspond to the version you have installed, the priority will be based on the version, so version 12 has 120 priority, 11 has 110, and so on. In the end, 20 links are updated for each version!
Multi-line:
vers=<vers>; update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-"${vers}" "${vers}"0 \
--slave /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc /usr/bin/x86_64-linux-gnu-gcc-"${vers}" \
--slave /usr/bin/g++ g++ /usr/bin/g++-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-g++ x86_64-linux-gnu-g++ /usr/bin/x86_64-linux-gnu-g++-"${vers}" \
--slave /usr/bin/cpp cpp /usr/bin/cpp-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-cpp x86_64-linux-gnu-cpp /usr/bin/x86_64-linux-gnu-cpp-"${vers}" \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-gcc-ar x86_64-linux-gnu-gcc-ar /usr/bin/x86_64-linux-gnu-gcc-ar-"${vers}" \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-gcc-nm x86_64-linux-gnu-gcc-nm /usr/bin/x86_64-linux-gnu-gcc-nm-"${vers}" \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-gcc-ranlib x86_64-linux-gnu-gcc-ranlib /usr/bin/x86_64-linux-gnu-gcc-ranlib-"${vers}" \
--slave /usr/bin/gcov gcov /usr/bin/gcov-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-gcov x86_64-linux-gnu-gcov /usr/bin/x86_64-linux-gnu-gcov-"${vers}" \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-gcov-dump x86_64-linux-gnu-gcov-dump /usr/bin/x86_64-linux-gnu-gcov-dump-"${vers}" \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-gcov-tool x86_64-linux-gnu-gcov-tool /usr/bin/x86_64-linux-gnu-gcov-tool-"${vers}" \
--slave /usr/bin/lto-dump lto-dump /usr/bin/lto-dump-"${vers}" \
--slave /usr/bin/x86_64-linux-gnu-lto-dump x86_64-linux-gnu-lto-dump /usr/bin/x86_64-linux-gnu-lto-dump-"${vers}"
Single line:
vers=<vers>; update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-"${vers}" "${vers}"0 --slave /usr/bin/x86_64-linux-gnu-gcc x86_64-linux-gnu-gcc /usr/bin/x86_64-linux-gnu-gcc-"${vers}" --slave /usr/bin/g++ g++ /usr/bin/g++-"${vers}" --slave /usr/bin/x86_64-linux-gnu-g++ x86_64-linux-gnu-g++ /usr/bin/x86_64-linux-gnu-g++-"${vers}" --slave /usr/bin/cpp cpp /usr/bin/cpp-"${vers}" --slave /usr/bin/x86_64-linux-gnu-cpp x86_64-linux-gnu-cpp /usr/bin/x86_64-linux-gnu-cpp-"${vers}" --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-"${vers}" --slave /usr/bin/x86_64-linux-gnu-gcc-ar x86_64-linux-gnu-gcc-ar /usr/bin/x86_64-linux-gnu-gcc-ar-"${vers}" --slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-"${vers}" --slave /usr/bin/x86_64-linux-gnu-gcc-nm x86_64-linux-gnu-gcc-nm /usr/bin/x86_64-linux-gnu-gcc-nm-"${vers}" --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-"${vers}" --slave /usr/bin/x86_64-linux-gnu-gcc-ranlib x86_64-linux-gnu-gcc-ranlib /usr/bin/x86_64-linux-gnu-gcc-ranlib-"${vers}" --slave /usr/bin/gcov gcov /usr/bin/gcov-"${vers}" --slave /usr/bin/x86_64-linux-gnu-gcov x86_64-linux-gnu-gcov /usr/bin/x86_64-linux-gnu-gcov-"${vers}" --slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-"${vers}" --slave /usr/bin/x86_64-linux-gnu-gcov-dump x86_64-linux-gnu-gcov-dump /usr/bin/x86_64-linux-gnu-gcov-dump-"${vers}" --slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-"${vers}" --slave /usr/bin/x86_64-linux-gnu-gcov-tool x86_64-linux-gnu-gcov-tool /usr/bin/x86_64-linux-gnu-gcov-tool-"${vers}" --slave /usr/bin/lto-dump lto-dump /usr/bin/lto-dump-"${vers}" --slave /usr/bin/x86_64-linux-gnu-lto-dump x86_64-linux-gnu-lto-dump /usr/bin/x86_64-linux-gnu-lto-dump-"${vers}"