Centos 7 how get alternatives list for java

12,704

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)

Share:
12,704

Related videos on Youtube

UnRealCloud
Author by

UnRealCloud

Updated on June 04, 2022

Comments

  • UnRealCloud
    UnRealCloud almost 2 years

    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 not 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)
    
    • Stephen C
      Stephen C over 5 years
      Umm ... am I missing something? Can't you just get your script to run alternatives --config java if you want the user to choose, or alternative --set java <path>?
    • Stephen C
      Stephen C over 5 years
      Anyhow, this shouldn't be tagged with java since it is entirely about wrangling the alternatives command.
    • UnRealCloud
      UnRealCloud over 5 years
      I don't run run alternatives --config java, because it requires user input .You can use alternatives --set <name> <path>
    • Stephen C
      Stephen C over 5 years
      Correct. So what is your question?
    • UnRealCloud
      UnRealCloud over 5 years
      I don't want an user to choose which version, I want launch a script who require a specific version of openjdk, so I want to know if an alternative exits for this version. I need to get what usually you get with the command alternatives --list java , but for some reasons doesn't work here .
    • Stephen C
      Stephen C over 5 years
      If you want your script to use a specific version of Java, you don't use "alternatives". You simply add the path to the required version to the script's $PATH ... or use an absolute pathname. And there are various symlinks to help you do this.
    • Stephen C
      Stephen C over 5 years
      Sorry ... but alternatives is not smart enough to do this kind of thing. You are better off just using your knowledge of how the standard openjdk symlinks work for your OS platform.
    • UnRealCloud
      UnRealCloud over 5 years
      Ok, that's clearer, thank you; But do you have an idea why alternatives --list doesn't work?
    • Stephen C
      Stephen C over 5 years
      Because it doesn't. The --list option is designed to list all link groups and what they are currently configured to. It don't take a <name> argument. Like the --help output and the manual entry both say.
    • UnRealCloud
      UnRealCloud over 5 years
      But in the synopsis there is alternatives [options] --list name, this is what fooled me
    • Stephen C
      Stephen C over 5 years
      True. That's a documentation bug.
    • UnRealCloud
      UnRealCloud over 5 years
      Ok, well thank you very much for your time given, I'hv learn a lot, it's a great day !