JDK Version inconsistent - java

My os is Ubuntu 16.04 LTS.
$ cat /etc/profile # part content of this file
JAVA_HOME=/usr/local/java/jdk1.8.0_101
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
$ echo $JAVA_HOME
/usr/local/java/jdk1.8.0_101
$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
$ ls /usr/local/java/
jdk1.7.0_79/ jdk1.8.0_101/
Why is my java version still jdk7?

Ubuntu has ability to work with multiple java versions. In your case, it just means that it has both JDK 7 and JDK 8 installed in your system but is using JDK 7.
To switch from one java version to another, you can use sudo update-alternatives --config java. This will list all JDKs installed in your system, just enter the number corresponding to JDK 8 and it should switch to JDK 8.

Run which java in your command shell. That will tell you where the java command you are running is coming from.
I suspect that is will tell you "/usr/bin/java" ... because this:
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
puts your new bin directories onto the end of the search path, not the beginning.
However, the better way to do this would be to use alternatives as suggested by another Answer. (With a custom installation in "/usr/local" this will require some fiddling around to get "alternatives" to understand the alternative.)

Related

Need help installing Java 8 on Mac OS X

I am trying to upgrade to: Java 8 Update 66, from Java 6, on my Mac running Mac OS X 10.10.5. I downloaded the Java Update .dmg file: re-8u66-macosx-x64.dmg. When I run the installer I get the message it installed properly. When I confirmed the install via the FireFox Browser at this URL:
https://java.com/en/download/installed.jsp
It reports:
Congratulations!
You have the recommended Java installed (Version 8 Update 66).
However, If I open a terminal window and enter: java -version
It reports:
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)
Can someone please explain what is going on here? Do I need to update a link somewhere?
Thanks.
Please check your PATH variable, and make sure that the java directories in the path match the directories in your computer. It should be the bin folder of the JAVA_HOME environment directory. Also check that JAVA_HOME environment variable is set to the jdk folder of your java installation.
There's two option based on my experience to fix this issue, fisrt uninstalled the java on your computer and reinstalled using the latest version.
Second, run a different version of Java, either specify the full path, or use the java_home tool:
List your installed java version:
$ /usr/libexec/java_home -V
In this case you are using java 8 so you can run command
$ /usr/libexec/java_home -v 1.8 --exec javac -version
If you want to make easy to switch your java version you can create alias in ~/.bashrc
alias java6="export JAVA_HOME=$(/usr/libexec/java_home -v 1.6);echo 'using Java 6'"
alias java8="export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);echo 'using Java 8'"
Hope it help

Raspberry pi update the java path

I installed the last image "RASPBIAN Debian Wheezy" on my Pi and it contains java 8
After that I installed java 7:
and I want to modify the java path from java 8 to java 7
So I updated my environment variables to:
export JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf/bin/java
export PATH=$PATH:/usr/lib/jvm/jdk-7-oracle-armhf/bin
I added them to my ~/.bashrc
but still when I execute java -version I got the java 8, even after reboot:
java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)
and when I display my envirnment variables, I got the java 7!:
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/jdk-7-oracle-armhf/bin
pi#raspberrypi /usr/bin $ echo $JAVA_HOME
/usr/lib/jvm/jdk-7-oracle-armhf/bin/java
How can I update the path so that the command "java -version" gave me the java 7?
You need to use update-alternatives
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-7-oracle-armhf/bin/java" 1
sudo update-alternatives --set java /usr/lib/jvm/jdk-7-oracle-armhf/bin/java
If still having problems check here http://www.element14.com/community/docs/DOC-54112/l/java-on-the-raspberry-pi
Simply, your PATH is in the wrong order. The conventional way would be:
export JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf
export PATH=$JAVA_HOME/bin:$PATH
Note that I prepended your new java. Since PATH is searched in order, it would still find the old java first, otherwise.

OSX Java upgrade doesn't reflect command line -version. Why?

I upgraded java on my osx 10.9.4 machine using the suggested method from the java web site
It successfully updated, but when trying to run Eclipse I get an error:
Version 1.6.0_65 of the JVM is not suitable for this product.
Version 1.7 or greater is required.
When I access java settings through the applet in the control panel, it shows Java 7 Update 65, but when I type java -version in the console, it shows 1.6.0_65 (response shown below):
| => java -version
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)
As far as I know, there is only one java on the box. "which java" returns /usr/bin/java and type -a java returns only /usr/bin/java also. /usr/bin/java is obviously the older version, but I'd like to use the updated one. Can someone please tell me how to update the /usr/bin/java version and/or how to link the applet version so that Eclipse will use the updated one?
Take a look at oracle documentation here:
http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html
It says:
To run a different version of Java, either specify the full path, or
use the java_home tool:
/usr/libexec/java_home -v 1.7.0_06 --exec javac -version
The /usr/libexec/java_home is a link to your jdk directory that should be located under:
/Library/Java/JavaVirtualMachines/jdk<major>.<minor>.<macro[_update]>.jdk
I think your java_home link is pointing to your jdk6. You can check it doing a ls -l /usr/libexec/

which JDK is installed

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.

how to tell which java version cgywin use?

i have cgywin and java 7 installed on window 7, also updated the system environment variable to point to the right java version, however when I run commands in cgywin, I m not sure which java it use, here is the commands and results:
$ java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode)
$ javac -version
javac 1.7.0_17
$ which java
/cygdrive/c/Windows/system32/java
export
declare -x JAVA_HOME="C:\\Program Files\\Java\\jdk1.7.0_17"
why all the versions are different?
Your PATH has two directories where it can find java one is under windows which picks a version installed (I imagine using the registry) and another is in your JDK. There is no javac in your Windows directory so it finds the on in your JDK.
To keep things simple I would just have one version of Java 7 JDK installed unless you really need multiple versions. I would change your path so it have the version of Java you want first, rather than near the end.

Categories