This may seem trivial but I haven't been able to find a fix.
I've installed the latest Java runtime environment but when I run java -version on the command line, I still get Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
However, when I test my Java version in browser, it works fine.
How can I get Terminal using the latest java version?
see Installed Java 7 on Mac OS X but Terminal is still using version 6
maybe you need to select the java version you want to see.
I am assuming you are using windows..
from your command line
echo %PATH%
make sure your java PATH is pointing your latest java bin folder.
I am not sure about the Mac but Can you verify if you have symlink setup under /usr/bin?
ex. /usr/bin/java -> java_path
Maybe you can change this symlink to point to the latest java you have installed.
Related
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
There is something going wrong with my java configuration and it is really bugging me. I am using IntelliJ IDEA and after downloading and installing java 8 I tried to configure my project to use that SDK but I could only locate version 1.6 under /Library/Java/JavaVirtualMachines/. I am new to OS X and I am really confused with the paths.
Looking on my Java control panel I can see I got installed Java 8 but after running java -version on the terminal I get 1.6.0_65.
And the which java gives back /usr/bin/java.
Please help I am completely lost
Here is an example with several Java versions installed side-by-side ...
ls /Library/Java/JavaVirtualMachines/
jdk1.7.0_25.jdk jdk1.7.0_72.jdk jdk1.8.0_05.jdk jdk1.8.0_25.jdk
User can edit ~/.profile to point explicitly at one
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_72.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
And here is result ...
java -version
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)
Well something was wrong with the installation. I completely removed the other versions (not 1.6) and reinstalled 1.8 using the default path (as there is no option to change it during installation. Now IntelliJ can see JDK 1.8
Thanks for the help anyway
I currently have CDH 5 installed on CentOS 6.5 with java jdk1.7 and I am trying to get CDH to use jdk1.8.
I do know that Java 1.8 is not a recommended version of CDH, but it is only a test cluster, so it isn't a big deal.
I have installed both Java 1.7 and Java 1.8 from Oracle's website using the RPM installation, so both versions of Java are currently under /usr/java. Using ls -ld my Java directory looks like:
/usr/java/default -> /usr/java/latest
/usr/java/jdk1.7.0_75
/usr/java/jdk1.8.0_31
/usr/java/latest -> /usr/java/jdk1.8.0_31
I also have script set up in /etc/profile.d to set $JAVA_HOME to /usr/java/default. The contents of my profile.d script:
export JAVA_HOME=/usr/java/default
export PATH=${JAVA_HOME}/bin:${PATH}
So when felt that I have this right, I run:
$ which java
/usr/java/default/bin/java
Telling me that it is pointing to the version of Java symlinked in default. And to determine which version of java is running, I run:
$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
And I can see that I have Java 1.8 currently running.
Everything seems great, except when I try to start a Hadoop service. The easiest to start is ZooKeeper, because it only has one service. HDFS has multiple servers so it is more work that to just start and stop ZooKeeper.
Starting ZooKeeper is done with the following command:
$ sudo service zookeeper-server start
Then to check which version of java it is running, I search the running processes list for java:
$ ps -ef | grep java
495 7170 1 7 12:27 ? 00:00:00 /usr/java/jdk1.7.0_75/bin/java -Dzookeeper.datadir.autocreate=false -Dzookeeper.log.dir=/var/log/zookeeper -Dzookeeper.root.logger=INFO,ROLLINGFILE -cp /usr/lib/zookeeper/bin/../build/classes:/usr/lib/zookeeper/bin/../build/lib/*.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12.jar:/usr/lib/zookeeper/bin/../lib/slf4j-log4j12-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/slf4j-api-1.7.5.jar:/usr/lib/zookeeper/bin/../lib/netty-3.2.2.Final.jar:/usr/lib/zookeeper/bin/../lib/log4j-1.2.16.jar:/usr/lib/zookeeper/bin/../lib/jline-0.9.94.jar:/usr/lib/zookeeper/bin/../zookeeper-3.4.5-cdh5.3.0.jar:/usr/lib/zookeeper/bin/../src/java/lib/*.jar:/etc/zookeeper/conf::/etc/zookeeper/conf:/usr/lib/zookeeper/*:/usr/lib/zookeeper/lib/* -Dzookeeper.log.threshold=INFO -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /etc/zookeeper/conf/zoo.cfg
I know that runs off the screen, bu the important part is that Zookeeper is being started by /usr/java/jdk1.7.0_75/bin/java.
To fix this, I have tried a few things:
Looking at the conf files for Hadoop and ZooKeeper under /etc/hadoop/conf and /etc/zookeeper/conf, respectively.
I found nothing setting JAVA_HOME.
Looking at the /usr/bin/zookeeper script to see if JAVA_HOME was set elsewhere,
I did find the script /usr/lib/bigtop-utils/bigtop-detect-javahome has the ability to set JAVA_HOME, but my profile.d script overrides that.
Manually moving /usr/java/jdk1.7 to /tmp.
Sadly, this is the only thing that works. When I move the jdk1.7 dir to another directory, and start ZooKeeper, it will use Java 1.8. Moving the jdk1.7 dir back, reverts to ZooKeeper using Java 1.7.
Has anyone dealt with this problem and does anyone know how to deal with this? I feel that I have Java set up correctly, but something is telling ZooKeeper/Hadoop to use an old version of Java?
I came here because I was looking for ways to upgrade JDK from 1.7 to 1.8 on the latest Coudera QuickStart VM 5.8 (can't believe they still ship it with JDK1.7 by default!). The hints and suggestions in the above answers helped tremendously - but since they were not listing complete steps to achieve the upgrade - I thought I would add that to help others like me.
So, here is a complete set of steps to upgrade Cloudera QuickStart VM from JDK1.7 to 1.8:
check your current JDK version - out-of-the-box it is:
[cloudera#quickstart ~]$ java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
download desired version of JDK1.8.xx - in my case: jdk-8u111-linux-x64.tar.gz
as user 'cloudera':
untar and move the resulting jdk1.8.0_111 dir to the /usr/java dir:
tar xzf jdk-8u111-linux-x64.tar.gz
sudo mv -f jdk1.8.0_111 /usr/java
shutdown all Hadoop services:
$ for x in `cd /etc/init.d ; ls hadoop-*` ; do sudo service $x stop ; done
update bigtop-utils file - set JAVA_HOME to your new JDK:
sudo vi /etc/default/bigtop-utils
updated lines:
# Override JAVA_HOME detection for all bigtop packages
export JAVA_HOME=/usr/java/jdk1.8.0_111
update 'cloudera' user's .bash_profile - export JAVA_HOME and add update PATH:
export JAVA_HOME=/usr/java/jdk1.8.0_111
PATH=$JAVA_HOME/bin:$PATH:$HOME/bin
export PATH
restart your VM
check Java version - should be the 1.8 one now:
[cloudera#quickstart ~]$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
By the way, I did not setup the /usr/java/default with the 'latest' sym link as #milk3422 did, for the sake of simplicity, but it would have worked just as well.
thanks!
I hate to answer my own questions, but here is the answer:
The wrong version of $JAVA_HOME is getting set for 2 reasons:
Using the command service removes most environmental variables. From man service:
service runs a System V init script in as predictable environment as
possible, removing most environment variables and with current work-
ing directory set to /.
The /usr/lib/bigtop-utils/bigtop-detect-javahome script has the ability to be configured with the environment variable BIGTOP_JAVA_MAJOR to manually set which version of Java to use. I tried setting this as an environment variable, but service removes it :(. It is also important to note that this script will find all versions of java installed, but the order of preference is Java 6, Java 7, Java 8, Open Java. So if you have Java 6, and 8 installed, it will prefer 6 over 8.
In short, to fix my problem, I added the following to the top of /usr/lib/bigtop-utils/bigtop-detect-javahome:
BIGTOP_JAVA_MAJOR=8
You can also set JAVA_HOME in this file to specify a specific version or path.
I had the same problem. I set
JAVA_HOME=... below the file /usr/lib/bigtop-utils/bigtop-detect-javahome
to override the default detect value. That works great!
Java is configurable in the web UI. Open Cloudera Manger --> Hosts --> Configurations --> Advanced, then set the JAVA HOME. This overrides the CDH's Java detection mechanism.
When I type java -version in the console I get java version "1.8.0_05". The soft link /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK points to /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents. In the java preferences window, the only listed version of Java is 1.8. JAVA_HOME is set to /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home.
However, when I try to run Eclipse.app, I get the error: Version 1.6.0_65 of the JVM is not suitable for this product. Version: 1.7 or greater required.
I believe it is trying to use /System/Library/Java/JavaVirtualMachines and in that directory the only version is 1.6.0.jdk.
How can I get eclipse to use the correct version of Java?
I solved this issue in my mac with yosemite:
Installed JDK for MACOSX 64bits from https://jdk8.java.net/download.html
Inside the eclipse.ini I put this line:
-vm /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
And it worked for me!
Download the 64-bit version of Eclipse instead of the 32-bit version.
The reason is that Eclipse contains native machine code (for the GUI) which is why there is both a 32-bit and 64-bit version of Eclipse, and this explicitly require the corresponding Java version. Originally Apple created both versions up to Java 6, but Oracle only creates a 64-bit version (much to the dismay of owners of older machines). So, if you download a 32-bit version of Eclipse it will only run with an Apple JVM, which apparently is too old (which surprise me - I thought Java 6 was still supported for Eclipse 4.4)
I faced this same problem but rather than making it to use version 1.8 I changed the settings in eclipse.ini file so I can just run the program regardless which version of jvm does it want to use
Solution:
Open the directory where you have Eclipse copy in your computer.
You would see a file name eclipse press control key and click on it to see the options.
Then click on Show Originalfrom the options, there you would find eclipse.ini file open it with a text editor and change the -Dosgi.requiredJavaVersion=1.7 to -Dosgi.requiredJavaVersion=1.6
Save the file and open the ecplise.app it should open now without any error
Try adding the following lines to your eclipse.ini:
-vm
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
Maybe a newer version of eclipse could help, too (if yours is out of date).
Take a look in your System Preferences -> Java. It should open the Java Control Panel. In the panel, check if you have one (or many) JDKs.
I suspect you have many and are setting the JDK in your .profile while Eclipse is reading some other Java Home.
You can change them manually by running this in your terminal
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
To check if it worked, run java -version and you should see something like
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
Try calling Eclipse now from the command line. To call Eclipse as an App, just set the Java8 through the Java Control Panel. This will be read when Eclipse starts.
This is what I have on my Java Control Panel:
This is on my Eclipse Luna:
Download the 64-bit version of Eclipse.
This solved the problem. Thanks everyone.
I normally still use Java 7 for all my coding projects (it's a company "politics" issue), but I installed Java 8 for one third-party project I am contributing to. Now, it seems I cannot have Java 8 installed in Windows 7 x64, and still use Java 7 by default:
C:\>"%JAVA_HOME%\bin\java.exe" -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
C:\>java.exe -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
As you can see, JAVA_HOME is completely ignored.
I also have Java in the path, using "%JAVA_HOME%\bin", which resolve correctly to Java 7 when I check the path in a DOS box, but it still makes no difference.
I checked in the "Java Control Panel" (not sure if this affects the default command-line Java version). Under the "Java" tab, the "View..." button, you get to see "registered" Java versions. I can add all the versions under the "User" tab, but under "System" there is only Java 8, and no way to change it.
Am I missing something, or did Oracle just make it impossible to use Java 7, unless I de-install Java 8? I don't want to have to specify the "source" and "target" everywhere, and I don't even know if it is possible for me to specify it everywhere, where Java is used.
EDIT: What I did is I de-installed all Java. Then installed the latest Java7 (both 86 and x64), and then the latest Java8 (both 86 and x64). After I did that, I noticed that the x64 JDK was gone. It seems Java8 killed it. So I re-installed the JDK 7 x64, after the JDK 8 x64. Still, JDK7 x64 did not seem to "replace" the "java.exe" which is copied into the "Windows" directory itself (I assume THAT is the problem).
When you install jdk8 it adds an entry like this
C:\ProgramData\Oracle\Java\javapath
to beginning of your PATH environment variable, removing this entry should resolve your problem.
You can select the JRE version from the command line with the -version: option.
> java -version:"1.7" MyClass
should select the 1.7 JRE if installed properly.
The list of the properly installed JRE is in the registry, see the key :
HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment (32bit)
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java Runtime Environment (64bit)
You can set the "CurrentVersion" there if you want a different default version than the latest.
See http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html#options
Don't modify your PATH to point to a particuliar JRE, let the special java.exe in Windows/system32 do the job.
Windows and Unix both find programs using their PATH environment variable. You have an java.exe in your Windows\System32 which is appearing before your "preferred" version of Java.
Change the PATH to be the one you need, or specify the full path when you need a different version.
2 Steps
1
Change registry key **HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\CurrentVersion** to point to 1.7
2
Copy java.exe,javaw.exe and javaws.exe from your java 1.7 version to Windows\System32 folder
(Since the corresponding files of java 1.8 are already there, you might have to overwrite with admin permissions)
3
(OOps actually not required 3rd step )
Open a new cmd window and check
java -version
Looks like you have to check where in your PATH is located your JAVA_HOME variable, the PATH is evaluated from left to right. A tip for you is to do all your Java system variables configuration at the beginning of your PATH.
PATH = %M2_HOME%\bin;%JAVA_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;...
Probably that's why after doing this:
- java -version
you are getting this:
- java version "1.8.0_05"
because there are other areas in your PATH that are pointing to other java.exe, for example C:\Windows\System32 or C:\ProgramData\Oracle\Java\javapath etc.
I had to make 2 changes for it to work:
Changed the Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion' to 1.7 from 1.8
The Java 8 installation adds a new entry to the PATH environment variable 'C:\ProgramData\Oracle\Java\javapath'. I removed this entry from the PATH.