Linux `alternatives --config` without user input

I am writing a RHEL kickstart script, and in my %post, I need to install a JRE.

Basically, the current setup involves me needing to manually go in after first boot and set the newly installed JRE as the default using the alternatives --config command. Is there a way for me to pass arguments to alternatives so I don't have to manually pick the correct JRE?


Solution 1:

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.

Solution 2:

You can use alternatives --auto <name> to automatically select the highest priority option.

An example:

 alternatives --install  /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/javac javac /usr/java/latest/bin/javac 10
 alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 20
 alternatives --auto javac

Would select the higher priority version (20) /usr/java/latest/bin/javac