javacentoscentos7

Centos 7 how get alternatives list for java


I would like to get the list of all alternatives for java versions, choose one and set it in a script, but option --list doesn't work as expected:

alternatives --list java
alternatives version 1.7.4 - 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>]
                    [--family <family>]
                    [--slave <link> <name> <path>]*
       alternatives --remove <name> <path>
       alternatives --auto <name>
       alternatives --config <name>
       alternatives --display <name>
       alternatives --set <name> <path>
       alternatives --list
common options: --verbose --test --help --usage --version --keep-missing
                --altdir <directory> --admindir <directory>

For the moment I create my own list with /etc/alternatives, but I'm not satisfied. How can I get a list like :

# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
 + 1           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java)
*  2           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java)

Solution

  • 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)