Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Code in bash script that changes version of java

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”

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What should I add to it to work?

>Solution :

/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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading