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.
Answer from Sam Varshavchik on Stack OverflowI would try cleaning it up manually. I've never done this so make sure you backup beforehand.
- Remove the link from /etc/alternatives
- Remove the relevant file from the admin directory
- /var/lib/dpkg/alternatives/ on ubuntu (debian may be the same but check the man pages under the FILES section)
- /var/lib/alternatives/ on CentOS 6&7
Removing them manually resulted in ... is already managed by ... error in my case. Aside from that, the manual removal also didn't scale, as i've had added multiple multiple alternatives for the centralized symlink. It's just a mess.
When it comes to either update-alternatives or alternatives, they both provide the --remove and --remove-all flags. As for the former flag, it only removes one single alternative of the link group. For example
$ update-alternatives --list python3
/usr/bin/python3.8
/usr/bin/python3.9
$ sudo update-alternatives --remove python3 /usr/bin/python3.9
$ update-alternatives --list python3
/usr/bin/python3.8
The form of the --remove flag goes by
update-alternatives --remove symlink-generic-name /path/to/one/executable/alternative
However, if you want to outright erase the generic name with all of its associated alternatives all at once, then --remove-all is the way to go.
$ update-alternatives --list python3
/usr/bin/python3.8
/usr/bin/python3.9
$ sudo update-alternatives --remove-all python3
$ update-alternatives --list python3
update-alternatives: error: no alternatives for python3
$ update-alternatives --query python3
update-alternatives: error: no alternatives for python3
Basically it says to your machine to use this alternative of Jave JDK instead of the default one, which, in Linux systems, is OpenJDK.
A brief extract from the man page is better than any answer I could write:
update-alternatives creates, removes, maintains and displays information about the symbolic links comprising the Debian alternatives system.
It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice for an editor to invoke if the user has not specified a particular preference.
Debian's alternatives system aims to solve this problem. A generic name in the filesystem is shared by all files providing interchangeable functionality. The alternatives system and the system administrator together determine which actual file is referenced by this generic name. For example, if the text editors ed(1) and nvi(1) are both installed on the system, the alternatives system will cause the generic name /usr/bin/editor to refer to /usr/bin/nvi by default. The system administrator can override this and cause it to refer to /usr/bin/ed instead, and the alternatives system will not alter this setting until explicitly requested to do so.
With --install you specified a link, "/usr/bin/java" a name "java" and a path "/usr/lib/java/JDK...." and you add a group of alternatives to the system. link is the generic name for the master link, name is the name of its symlink in the alternatives directory, and path is the alternative being introduced for the master link.
I hope to be clear enough, Here there is a post regarding java alternatives.
For the complete usage list I suggest to look at the same manual page, typing man update-alternatives on your OS shell;
i want to explain it for you from scratch ... if you have 2 or more versions of a program that starts with a same command in linux you can use update-alternatives command for determining the default version of that program and you can also change the default version of that command easily .. assume that you have 2 version of python on your system. python 2 & python 3. by default python command on linux starts the python2 interpreter on the shell . you think that python 2 is old and you want to use python 3 instead of python2 . one of the solution is that you enter python3 command on the shell and start the python interpreter that its version is more than 3 ... but you want to enter python command and shell recognize that you want to run python3 interpreter . here,update-alternatives command do it's work and determine the default version and versions of a program you want to use for a specific command .
i told you that python command start python 2 interpreter by default . you want to change it . follow the example :
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 1.
when you execute this command on linux you are telling to shell that after this time two links of two different programs are linked to python command on linux .. infact you install the python3 program on python command on linux and two programs exist at 1 command that you can change the defaults of these programs and run what of these programs you want by changing priority in command or configure it manually to set the default program ..
hope this is useful for you !
Add python2.6 to alternatives:
sudo alternatives --install /usr/bin/python python /usr/local/bin/python2.6 5
Then set python3.9 as defaut:
sudo alternatives --config python
Or override the symlink with the desired python version:
sudo ln -fs /usr/bin/python3.9 /usr/bin/python
Late to the party but to me the good practice for this is to run
sudo alternatives --install /usr/bin/python3 python3 /bin/python3.9 99
Since you are trying to update the alternatives for python 3.x version it makes sense to use the python3 link instead of the python one.
After installing the alternative, configure it with:
sudo alternatives --config python3
And in the end:
sudo alternatives --config python
To configure the python link to point to python3 using alternatives
On Debian (but not Fedora or RHEL), to see a list of all "master alternative names":
update-alternatives --get-selections
--get-selectionslist master alternative names and their status.
And for each of those listed, you can run --list $ALTERNATIVE_NAME, e.g.
update-alternatives --list editor
--list nameDisplay all targets of the link group.
If you would like to see a list of all alternatives in their respective groups, you could run the following in fish shell:
for alternative in (update-alternatives --get-selections)
echo $alternative
update-alternatives --list (echo $alternative | cut -d" " -f1)
echo
end | pager
The (ba|z)?sh syntax should be something similar.
To change the alternatives, run sudo update-alternatives --config $ALTERNATIVE_NAME
The exact answer is (RHEL):
ls /var/lib/alternatives
Directory /etc/alternatives maintains flat long list of all symlinks mixing masters and slaves together. Slave symlinks cannot be used with alternatives --display [symlink] command.
At the same time directory /var/lib/alternatives contains status information (including master-slave relationship) for each group in shortened list of file names all of which can be directly used with --display option. For example, /var/lib/alternatives/java:
alternatives --display java
It appears than the option --list doesn't take arguments, it's a bug in the manual synopsis.Moreover for manage my java versions I should try env variables.
(The bug has been reported as https://github.com/fedora-sysv/chkconfig/issues/11)
Use this command alternatives --list to get available versions on cli.
[root@88a15b43eab2 /]# alternatives --list
ld auto /usr/bin/ld.bfd
libnssckbi.so.x86_64 auto /usr/lib64/pkcs11/p11-kit-trust.so
jre_openjdk auto /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre
java auto /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre/bin/java
jre_1.8.0_openjdk auto /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64
jre_1.8.0 auto /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre
Does your version have --set?
--set name path
Set the program path as alternative for name. This is equivalent to --config but is non-interactive and thus scriptable.
Use grep:
update-alternatives --set java $(update-alternatives --list java | grep java-8)
or
update-alternatives --set java $(update-alternatives --list java | grep java-11)