I have setup my JAVA_HOME environment variable by $HOME/.profile this way:
export JAVA_HOME="$(/usr/libexec/java_home)"
Downloaded the release apache-ignite-fabric-2.5.0-bin.zip
Checking environment:
josepens-mbp:bin josepen$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home
josepens-mbp:bin josepen$ $JAVA_HOME/bin/java --version
java 10.0.1 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Everything seems fine, however when running bin/.ignite.sh get the following error:
josepens-mbp:bin josepen$ ./ignite.sh
./ignite.sh, ERROR:
The version of JAVA installed in JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home is incorrect.
Please point JAVA_HOME variable to installation of JDK 1.8 or JDK 9.
You can also download latest JDK at http://java.com/download
Is Ignite compatible with Java 10?
Ignite did not tested against JDK 10 and there might be unknown issues. It's recommended to use JDK 1.8 or 9.
But if you want, you may hack scripts and run on 10. For example in bin/include/functions.sh line 66 add java 10: "$JAVA" -version 2>&1 | grep -qE 'version "(1.8.*|9.*|10.*)"' and bin/ignite.sh line 154: ${JAVA_HOME}/bin/java -version 2>&1 | grep -qE 'java version "(9.*|10.*)"'.
Related
Summary
I have followed the advice given in this answer to create aliases which allow me to quickly switch between JVM versions on macOS. And I have cross-checked with this article, which suggests a similar solution. This works well for Java 15, but not for Java 8. See details below.
Details
Details of macOS version:
$ sw_vers
ProductName: macOS
ProductVersion: 12.1
BuildVersion: 21C52
Details of installed Java versions:
$ java --version
java version "15.0.1" 2020-10-20
Java(TM) SE Runtime Environment (build 15.0.1+9-18)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
15.0.1 (x86_64) "Oracle Corporation" - "Java SE 15.0.1" /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home
1.8.301.09 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
1.8.0_292 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home
And this is from my .zshrc:
# Aliases to quickly change active JVM version
export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8)
export JAVA_15_HOME=$(/usr/libexec/java_home -v 15)
alias java8="export JAVA_HOME=$JAVA_8_HOME"
alias java15="export JAVA_HOME=$JAVA_15_HOME"
# Set default to Java 15
java15
When I source the .zshrc file, there are no errors.
However, when I run the alias java8, I get the following error:
$ java8
export: not valid in this context: Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
And the active Java version has not changed, i.e., it is still 15.0.1 (my default).
At first, I suspected the version number in my alias was wrong. I have tried changing the name in my .zshrc to the fully qualified name (1.8.0_292):
export JAVA_8_HOME=$(/usr/libexec/java_home -v 1.8.0_292)
alias java8="export JAVA_HOME=$JAVA_8_HOME"
When I run the alias java8 again, after sourcing the updated .zshrc, I no longer get an error. But now my Java environment is in a broken state:
$ java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
$JAVA_HOME updates, though, so at least the alias works now:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
Fortunately, I can use my other alias, java15, to get my environment back in a working state:
$ java15
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home
$ java --version
java 15.0.1 2020-10-20
Java(TM) SE Runtime Environment (build 15.0.1+9-18)
Java HotSpot(TM) 64-Bit Server VM (build 15.0.1+9-18, mixed mode, sharing)
This indicates that the aliases are indeed working, at least java15. But, for some reason, java8 "refuses" to "activate," no matter what version number I put in my alias.
Note that I have installed the OpenJDK version for Java 8, because Oracle's versions are no longer available on their website, nor via Homebrew.
This is exactly how I installed Java 8 on my system, just in case it's relevant:
$ brew tap adoptopenjdk/openjdk
$ brew install adoptopenjdk8
Lastly, I am able to use Java 8 by "manually" specifying it for specific commands, e.g., when using Clojure/Leiningen. For example, this works fine:
$ JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home lein repl
This suggests that the Java 8 installation is indeed working correctly, and that the issue just has to do with my environment and .zshrc somehow.
Update
I discovered jEnv and tried to use that instead of aliases.
Unfortunately, that results in the same problem:
$ brew install openjdk#8
$ jenv add /usr/local/opt/openjdk#8/libexec/openjdk.jdk/Contents/Home
openjdk64-1.8.0.312 added
1.8.0.312 added
1.8 added
$ jenv local 1.8
$ jenv versions
system
* 1.8 (set by /Users/my-username/my-project-dir/.java-version)
1.8.0.312
15
15.0
15.0.1
17
17.0
17.0.1
openjdk64-1.8.0.312
openjdk64-17.0.1
oracle64-15.0.1
$ java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Oh, my goodness… The answer was in front of my nose all along:
"Unrecognized option: --version"
With Java 8, the command --version is invalid. Instead, I had to use -version. Newer versions of Java support both commands (with one or two -), which threw me off.
$ jenv global 17
$ java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)
$ java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment Homebrew (build 17.0.1+1)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.1+1, mixed mode, sharing)
$ jenv global 1.8
$ java --version
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-bre_2022_01_01_23_04-b00)
OpenJDK 64-Bit Server VM (build 25.312-b00, mixed mode)
That's the dumbest mistake I've made in a while.
I installed java 8 and openjdk 11 on my Mac. JAVA_HOME is set to java 8, but when running java --version, it points to openjdk 11. Why is it happens and how can I make java command point to java 8?
running the command
echo $JAVA_HOME
java --version
output is
/Library/Java/JavaVirtualMachines/jdk1.8.0_172.jdk/Contents/Home
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+11)
OpenJDK 64-Bit Server VM (build 11.0.8+11, mixed mode)
It is so wired.
export PATH=${JAVA_HOME}:${PATH}
Add this to ~/.zshrc. JAVA_HOME will be the first choice when running java.
I checked my java version from terminal .I got this information
Last login: Sun Mar 15 08:46:08 on ttys000
localhost:~ naveenkumar$ java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
localhost:~ naveenkumar$
I install new java 1.8 JRE .close my terminal .Agan i type java -version .I found the same version .
why ? how to upgrade java version.
You installed Java 8 but it didn't overwrite this: /usr/bin/java
The easiest way for you to solve this problem is to install Java 8 JDK, not JRE. After install JDK, your path should be automatically updated.
I have install JRE 1.8 from Oracle site. But there is no jre dir for it.
java -version still returns:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
When I open config app for it it shows this
1 . Add such shell to your $HOME/.bash_profile
alias setJdk6='export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)'
alias setJdk7='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)'
alias setJdk8='export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)'
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
2 . Run command source ~/.bash_profile
3 . Then type "setJdk7" to use JDK7, "setJDK8" to use JDK8
It turns out that it is not enough to install JRE on Mac OS to have it registered and listed by /usr/libexec/java_home -V command. You have to install full JDK for it.
On RHEL 6 64 bit, first I installed openJDK via yum and later I could validate the same by running rpm -qa | grep jdk
Later, I removed the openjdk and downloaded the Oracle jdk. Oracle gave me a .bin file which is a slef extraclter and installed java.
QUESTION: Now, how do I verify by looking at the installed java that this is coming from the oracle JDK and not the openJDK.
BTW, oracle provides a rpm for their JDK, but I chose to install it using .bin file.
Moderators, please move my question to superuser if you feel so. I chose to post on stack overflow as we have numerous Java programmers here who would easily know the answer.
EDIT:
Sorry, I already had run those commands but is does not say anything specific to Oracle:
# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
# javac -version
javac 1.6.0_45
# which java
/usr/bin/java
# whereis java
java: /usr/bin/java /etc/java /usr/lib/java /usr/share/java
# echo $JAVA_HOME
/usr/lib/jvm/java
First use which javac to see which binary is beeing used.
Then simply run javac -version to see which version you are running.
If the output mentions
Java HotSpot(TM)
Then it is most likely Oracle Java SDK.