Home > Enterprise >  Code in bash script that changes version of java
Code in bash script that changes version of java

Time:06-30

I have to preparae a script that

-switches the current Java to this one: /usr/bin/java

export PATH=$JAVA_HOME”$PATH” export JAVA_HOME=”/usr/bin/java”

What should I add to it to work?

CodePudding user response:

/usr/bin/java is not a directory, but an executable file.

The JAVA_HOME should point to Java's installation directory, if at all required. Most of the time, you don't actually need to define JAVA_HOME as it's only used by certain applications (such as Maven) to override the version of Java that would otherwise be found on the PATH.

So all you need to do is:

export PATH=/usr/bin:$PATH

and this will make the java command be taken from the /usr/bin directory. This is normally in your path anyway, but this line ensures it's at the start.

You may also need to delete any existing definition of the JAVA_HOME variable, as that would override /usr/bin/java when used by tools such as Maven.

  •  Tags:  
  • bash
  • Related