I need to be able to call a certain process with a certain java binary. Call that process "foo". However, foo also invokes several other processes via java, but foo is a black box to me. When foo invokes those processes, it just runs "java bar", "java bat", etc. How do I tell foo and any processes called by foo, to use /full/path/to/java only? Essentially I want to use "update-alternatives" for a single shell session and/or single process tree.

OS is Centos7, shell is bash.

Setting the system java is out of the question, as other processes on the system need a different java binary.

  • 1
    One method might be PATH=/custom/java/bin:$PATH foo assuming everything else in that directory is okay to list first in PATH and that foo or downstream of that do not fiddle with PATH on their own... – thrig Mar 10 '17 at 0:14

Create a directory ~/myjava that contains only a symbolic link to /full/path/to/bin/java.

mkdir ~/myjava
ln -s /full/path/to/bin/java ~/myjava/java

Run the process with this directory at the start of the command search path. In addition, some programs look at the environment variable JAVA_HOME. Make sure that it's consistent. The actual java executable should be in a subdirectory called bin or $JAVA_HOME.

PATH=~/myjava:$PATH JAVA_HOME=/full/path/to foo

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.