Issue installing Java 8 on Mac OS X - java

I am having an issue trying to upgrade to Java 8 from Java 6 on my Mac running Mac OS X 10.10.5, with Java 8 seemingly not getting recognized.
I installed Java 8 via the .dmg installer: jre-8u66-macosx-x64.dmg, yet when I enter: java -version, it reports:
java version "1.6.0_65".
Yet, I noticed under the Java Panel via System Preference, the Java Runtime Environment Settings Panel is displaying 1.8.0_102.
From poking around I have noticed:
1) Java 8 seems to have installed into: /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk
2) Java 6 seems to have been installed into:
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk
I then noticed a post on StackOverflow recommending to use "brew" to install Java, and not use the official installer for Mac, as it is broken. When I went to install brew I got this error message:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
I got this error message: Illegal variable name.
And then I read that "brew" is broken on versions of El Capitan and above.
So, what do I need to do to get this upgrade to Java 8 to work???
Appreciate any help with this! Thanks!

your java command points to the stub binary which uses current version configured
$ ls -la /usr/bin/java
lrwxr-xr-x 1 root wheel 74 Feb 5 2015 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
all you need is to update your JAVA_HOME(I've added that to my ~/.profile):
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
There's a topic which describes this in-depth Need help understanding Oracle's Java on Mac

set your JAVE_HOME to java 8.
For the brew thing, guess you might have run it in csh/tcsh..change it to bash and the script will working to install brew.

I don't know about the brew thing. Looks like you have two jdks and the one with /System/Library/Java/JavaVirtualMachines/1.6.0.jdk has the $PATH set for it but the new one you installed doesn't have its $PATH set for it yet. I would recommend following,
i. either delete the old one and then set the $PATH for new one
ii. just set the $PATH for new one but try to keep both JDK in same location
in both cases you want to have $JAVA_HOME yield the path for your latest jdk which should work.
here is link that might be helpful
https://cloudlink.soasta.com/t5/CloudTest-Knowledge-Base/Adding-JDK-Path-in-Mac-OS-X-Linux-or-Windows/ta-p/43867
for setting the $PATH for you. In plain terms, you have to find a file in your mac that is called .bash_profile and then in that file you have to set the $PATH for your new jdk or which ever jdk you want to work with. This should take little research if you don't know but its not very difficult. Hope this helps..

Related

How can Homebrew automatically update JAVA_HOME after it updates JDKs?

I'm using macOS, when homebrew updates the JDK I have to manually update the $JAVA_HOME path in .zshrc since it uses the version number in its path, just replace the version number to a newer one like
/usr/local/Cellar/openjdk#11/11.0.14/libexec/openjdk.jdk/Contents/Home
to
/usr/local/Cellar/openjdk#11/11.0.16/libexec/openjdk.jdk/Contents/Home
As you can see there is just a difference in version numbers, other directory names are still the same. Is there any way to automatically update JAVA_HOME to the path that Homebrew just updated?
You can use the default macOS command java_home:
% /usr/libexec/java_home -v 11
/opt/homebrew/Cellar/openjdk#11/11.0.16.1/libexec/openjdk.jdk/Contents/Home
And put this in your .zshrc:
export JAVA_HOME=`/usr/libexec/java_home -v 11`
From man java_home:
java_home - return a value for $JAVA_HOME
I eventually figured out what the problem is. I found a difference between openjdk#11 and adoptopenjdk11 installed with Homebrew.
The situation was I actually got 3 java paths on my mac, jre8, openjdk#11 and openjdk#8.
In my opinion, openjdk#{xx} is like unregistered binaries that are not bound with java_home (brew formulae), however, adoptopenjdk{xx} are more like registered ones(brew cask).
And what made this situation more complex is the jre8 downloaded from Download Java for macOS which pinned the java_home to
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
That is why I could not find any other JDK paths (other than the one I downloaded from the java official website) through executing
$ /usr/libexec/java_home -V
since it actually searches for and lists Java Virtual Machines which are included by JREs.
This relates to a common confusion that new developers sometimes would have - the difference between JDK JRE and even JVM (What is the difference between JDK and JRE?).
So the solution is installing adoptopenjdk{xx} if you are not strictly sticking with openjdk#{xx}, it would register the path of its JRE-contained JVM to the variable java_home , and it's ready to go with export in the bash/zshell profile.
Thanks to #Ortomala Lokni and #g00se as they provide useful info that inspired me to look deeper into this.

How to set Java version for SBT

I am trying to run a scala program, in which there are errors with Java 16. My colleague is using Java 15, and all is fine. When i type java -version in my terminal it says i am using Java 15. However, when i run sbt run -v, it says it is using Java 16, and thus the program throws errors.
I am seeing people talk about this sbt-extra thing, but not a whole lot of explanation on how to use it. I do not even have Java 16 installed on my Mac, so I am really confused as to why SBT says this.
I think I have faced a similar issue. It happened because you did not set the Java_Home part. If you are using a mac, you have to set Java_Home path in .bashrc or .zshrc file which one you are using. I think it should work.
To handle your installed jvms you can use Jenv.
To install jenv:
git clone https://github.com/jenv/jenv.git ~/.jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
Then, you can add your intalled jvms. In Mac, if you have installed them via brew you can find those in: /Library/Java/JavaVirtualMachines.
Then add them to jenv:
jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
You can see the available jvms in jenv:
you can set the default jvm with the command:
jenv global 1.8.0.121
Then, execute sbt in some of your projects and you should see that jvm as the jvm that sbt is using.
Another option which worked for me is to add the version of java you want to be used to the front of your terminal PATH environment variable. Since I used homebrew to install openjdk, I used the path they suggested resulting in the following path to use openjdk version 11.
export PATH="usr/local/opt/openjdk#11/bin:$PATH"
Note - the openjdk path I used I think is just the homebrew symlink to the actual java installation which is in /Library/Java/JavaVirtualMachines. You could probably just use that actual path but I didn't test it.

centOS 7: segmentation fault (core dumped) when type java -version

I have been fighting this problem for quite a long but could not get a solution. Had searched net but could not find anything concrete.
I have removed all openJDK1.8.0_xx from my system using yum remove java*.
Then I have installed Oracle Java i.e. jdk1.8.0_151 using standard methods i.e.
Download the .tar.gz and then unzip the same.
Change in /etc/profile and set the JAVA_HOME as follows:
export JAVA_HOME=/usr/java/jdk1.8.0_151
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Then source /etc/profile
After this when I type java -version I got Segmentation Fault (core dumped). When I type which java I got
/usr/bin/java
Note:
I had removed all symlinks of java and again created. Eg.
ln -s /usr/java/jdk1.8.0_151/bin.java /usr/bin/java
and then
ln -s /usr/jdk1.8.0_151/bin.java /etc/alternatives/java
Post that I have tried
update-alternatives --install /usr/bin/java java
/usr/java/jdk1.8.0_151/bin/java 1
Nothing happend!!! I still see that frustrating message when I check Java Version. Segmentation Fault (core dumped).
Can any body please share any light or thought on why is this happening?
I don't think there is a good answer to this. It sounds like the following bug report for Oracle Java SE 8u155:
https://bugs.openjdk.java.net/browse/JDK-8194180
The tentative diagnosis from the Oracle engineer was that some dependencies were missing. However, the reporter didn't provide more details and the bug report was closed as "unconfirmed".
My suggestions would be:
Download and install a later release of Oracle Java 8. (At the time of writing, the latest release was Java SE 8u221.)
Go back to using OpenJDK from the CentOS repos.
For the record, Oracle do certify Java 8 for RHEL 7.x (which is equivalent to CentOS 7.x) but only for 64-bit JVMs.
Source:
"Oracle JDK 8 and JRE 8 Certified System Configurations"

Getting R to use newer versions of java

This question is related to this other question.
I am trying to use RNetLogo with R and get the following error.
nl.path <- "/Applications/NetLogo 5.1.0"
NLStart(nl.path)
Error in .jnew("nlcon/Preprocess") :
java.lang.UnsupportedClassVersionError: nlcon/Preprocess : Unsupported major.minor version 51.0
From what I understood in this other question, the problem is that R is using an old version of Java which is incompatible with RNetLogo.
I installed Java 8.0 hoping to solve the problem but my understanding is that, despite Java 8.0 being installed on my computer (Mac OS Maverick), R does not pick it up and keep trying to use old versions of Java.
So my question is : How can I get R to use Java 8.0 instead of any older version?
In the terminal console, I get
java -version :
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Thanks in advance for your help,
Seems like on Mac OS X you can have multiple Java at a one time.
Use below command on terminal to check how many JDK version you have.
/usr/libexec/java_home -V
You can follow below instruction to have correct Java Path setup:
How To Set $JAVA_HOME Environment Variable On Mac OS X
In nutshell do:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Unfortunately, none of these seem to help on a Mac. Windows and Linux solutions are not relevant because the files are in different places.
If you just update to Java 1.8 (Java 8 for Oracle) in the standard way as prompted by the Java preferences pain, you just get the Java Runtime Environment (JRE). If you run...
/usr/libexec/java_home -V
...it still shows only java 1.6, and...
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
...throws an error saying it can't find a version 1.8.
To get the Mac to even recognize a newer version of Java, it seems you must install JDK v.8 (not JRE). At that point, you can get the Mac to recognize that a new java virtual machine is available, and you can do the export command successfully. (Note that the new 1.8 JVM is in a DIFFERENT place--/Library/Java instead of /System/Library/Java for 1.6.). BUT, this still does no good for R.
I've tried putting the export JAVA_HOME... command into my .profile and my .bash_profile. Then sourcing both. Works fine, but has no effect on R AFAICT. I've launched R via the standard Mac R GUI, from RStudio, and from the terminal and it is only recognizing Java 1.6. So RNetLogo still does not work.
I will try to find RNetLogo 1.0-0 in the archive and test that. If it works, I suggest that 1.0-1 be rolled back until this Java problem is solved.
I use this line on windows :
options(java.home="C:/Program Files/Java/jre7/")
You probably have to change the 7 for an 8 and find the proper path on the mac.
This supposedly works (originally from this blog entry):
1) Download and install Apple’s Java version 1.6.
2) Reconfigure your Java installation by using sudo R CMD javareconf -n.
3) Reinstall rJava from source with: install.packages('rJava', type='source').
Please acknowledge Will Lowe at conjugateprior.org for the original post and solution.
Try linking libjvm.dylib to /usr/lib:
sudo ln -f -s $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/lib
-f flag is added to force overwriting existing file/link
EDIT: I don't know if anyone is still struggling with this, but with rJava 0.9-9, the 'partial fix' below no longer works. What does work, and completely, is the final solution offered here: https://github.com/s-u/rJava/issues/86
Copying from there, many thanks to Gregory R. Warnes:
uninstall existing rJava versions by running the following in the Terminal:
Rscript -e 'remove.packages("rJava")'
sudo Rscript -e 'remove.packages("rJava")'
add the following to /Users/<userid>/.bashrc:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)/jre'
(e.g., type > vim /Users/<userid>/.bashrc in the Terminal, then 'i', add the line above, then ':wq' to save and quit)
close and re-start all Terminal, R and RStudio windows
type the following in the Terminal window:
sudo ln -sf $(/usr/libexec/java_home)/jre/lib/server/libjvm.dylib /usr/local/lib
in a new R session, re-install rJava from source:
install.packages("rJava", repos="http://rforge.net", type="source")
OLD 'PARTIAL FIX' BELOW:
Okay. I have been working on this problem all morning, and I have a partial fix.
I tried the solution suggested by Guilherme Kenji Chihaya above, but even after sudo R CMD javareconf -n and install.packages('rJava', type='source'), R insists on using Java 1.6 (and is happy to do so).
HOWEVER, R studio throws an error after re-installing rJava:
library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: #rpath/libjvm.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/rJava/libs/rJava.so
Reason: image not found
Error: package or namespace load failed for ‘rJava’
Googling this lead me to this post: http://andrewgoldstone.com/blog/2015/02/03/rjava/, with a working solution. Set the following in the Terminal:
alias r="DYLD_FALLBACK_LIBRARY_PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home/jre/lib/server/: open -a r"
And start R from the Terminal. Then, magically, in R:
> library(rJava)
> .jinit()
> .jcall("java/lang/System", "S", "getProperty", "java.runtime.version")
[1] "1.8.0_11-b12"
However, this only works when starting R from the Terminal. I haven't been able to get R to automatically recognise the right "DYLD_FALLBACK_LIBRARY_PATH" in any way.
In Ubuntu there is a command alternatives that i use it for this purpose.
alternatives --install /usr/bin/java java /usr/java/jdk1.8*/jre/bin/java 200000
alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8*/jre/bin/javaws 200000
alternatives --install /usr/bin/javac javac /usr/java/jdk1.8*/bin/javac 200000
alternatives --install /usr/bin/jar jar /usr/java/jdk1.8*/bin/jar 200000
After alternatives install use the following command to change your version.
alternatives --config java and then select your newer java.
If this is not available you should first find out what where is your new java actually.
locate *jdk1.8*
Then find out which java you run as binary. which java this will returns the path of binary. this is the old java binary, So remove it and link new java binary in the same place. For example : ln -s /path/to/java1.8*/bin/java /usr/bin/java
In addtion you need to update your CLASS_PATH environment variable that is necessary for the VM.
for example:
export CLASS_PATH=/usr/java/jdk1.8*/jre/lib and you can add this line in your bashrc file to register this configuration.
In Debian-based installations R uses /etc/R/Makeconf settings for building libraries. One of the setting there is JAVA_HOME. Try setting the correct path there and reinstall the package.

How to install JPype on OS X Lion to use with Neo4j?

I am trying to use Neo4j for a project, and want to interface with it through Python since I'm a newbie to programming and don't know any Java. I'm following the installation instructions, but I'm stuck on
the first step, which is to install JPype.
I'm using OS X 10.7 (lion). I think my configuration is pretty standard
with Python 2.7.2 downloaded from the Python website and Java 1.6.0 downloaded from the Apple website.
When I run
% sudo python setup.py install
On the JPype installer, I get about a 100 lines of error code about various .h files, then it
terminates with the lines:
lipo: can't figure out the architecture type of: /var/tmp//
ccwOzLi9.out
error: command 'gcc-4.2' failed with exit status 1
I found a blog post about a gcc error with JPype, but I followed the instructions there to no avail. I also emailed the author of that post, and he told me had never actually used JPype, had been working in OS X 10.6, and didn't have any insight.
I also emailed the creator of JPype, who told me that he only uses Windows, and has no idea how to make the install work on OS X. But if we can solve this, I can point him to the answer and maybe he can add the solution to the JPype documentation and help lots of other people as well!
So, anyone know what I'm doing wrong? I would like to use Neo4j, but I
don't know Java so I'm at a complete loss for how to fix a compiler
error.
Based on reading every Google result available, my two running
theories are that:
I'm somehow using a 32-bit version of Python or of Java (though I
used standard official installations and can't figure out how to
switch to 64-bit or if that's even possible)
The JPype files can only be compiled using GCC 4.0 instead of 4.2.
But I can't find anything online about how to rollback to GCC 4.0 (or
if it comes shipped with 2011 MacBooks and there is some way to force
JPype to compile with that instead).
There is another similar question, but the solution there is to use a different adapter that goes through REST instead of hooking directly into Java. I will try that if I have to, but I would really rather use the recommended Neo4j method if it's possible.
I'm not a Python guy, but tried installing JPype on my machine:
% uname -a
Darwin fatty-i7.local.tld 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug 9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64
% java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)
On OSX Lion, the latest JDK appears to be located here:
/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/JavaVM.framework/
A little googling turned up this post: http://blog.y3xz.com/post/5037243230/installing-jpype-on-mac-os-x
I followed those instructions to modify setup.py, then ran sudo python setup.py install with no problems.
Does that help?
On my Lion, the "include" directory in the JDK was gone, so JPype couldn't find jni.h.
I updated setup.py in two places, one to set where to find jar libraries:
def setupMacOSX(self):
self.javaHome = '/System/Library/Frameworks/JavaVM.framework'
self.jdkInclude = ""
self.libraries = ["dl"]
self.libraryDir = [self.javaHome+"/Home/lib"]
self.macros = [('MACOSX',1)]
And one to set where to find jni.h:
def setupInclusion(self):
self.includeDirs = [
self.javaHome+"/Headers",
<other stuff>
For me,
self.javaHome = '/System/Library/Frameworks/JavaVM.framework/Versions/Current/'
worked.
$ uname -a Darwin 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64
$ java -version java version "1.6.0_33" Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720) Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
Here are directions I put in my README to install JPype on OS X 10.7. Same idea as the answers here but different enough to warrant the submission.
The python interface to java (JPype) needs mods to the setup.py:
In summary, you need to make sure the JPype setup.py script can see your Java SDK "Headers" and "Home" directory
I had to install Java from Apple first since my default OS X installation did not come with Headers in the typical Java install path which I found by executing:
/usr/libexec/java_home
If you do happen to have a Headers dir, you probably do not need to reinstall Java and can set the path vars below based on your java HOME directory which is likely different from those in these directions
After I installed Java, I found the new installation in:
/Library/Java/JavaVirtualMachines/
My Home directory was:
/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Home/
and my Header directory was:
/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Headers/
1) The JPype script assumes that Headers is within the Home directory but it's not, so I changed the Home path var and created a new Content path var in the setup.py script - In setupMacOSX(self):
self.javaHome = '/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Home/'
self.javaContents = '/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/'
2) In setupMacOSX(self), change self.libraryDir:
self.libraryDir = [self.javaContents + "/Libraries"]
Note that this step was mentioned as required but I did not have to do this for it to work so maybe try without it first
3) In setupInclusion, add paths to your "Home/include" dir and your "Headers" dir:
self.javaHome+"/include",
self.javaContents + "/Headers",
4) Running the installation should now work:
sudo python setup.py install
For everyone who is still trying to install Jpype but has meanwhile updated Mac OS: Andreas Kolleger's answer just works fine, but with XCode 4.3 the path changed to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/JavaVM.framework/Versions/Current/
In ML it's MacOSX10.8.sdk. At least on my system. :)
For me, on Mountain Lion
self.javaHome = '/System/Library/Frameworks/JavaVM.framework/'
worked.
$uname -a
Darwin 12.0.0 Darwin Kernel Version 12.0.0: Sun Jun 24 23:00:16 PDT 2012; root:xnu-2050.7.9~1/RELEASE_X86_64 x86_64
$ java -version
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
I did the same, but choosing
self.javaHome = '/Developer/SDKs/**MacOSX10.6.sdk**/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/'
instead
self.javaHome = '/Developer/SDKs/**MacOSX10.7.sdk**/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/'
realize that I use version 6 vs 7. With the 7 version I got the same errors that the beginning.
To make Will's answer a bit more specific: I had to modify the setupInclusion(self) method by adding the directory path he suggested, ie, '/System/Library/Frameworks/JavaVM.framework/Headers' on Mountain Lion (java version 1.6). With that the installation of JPype succeeded (though gave a bunch of warnings...)
Here's what worked for me - recommend you put the first line in your profile.
export JAVA_HOME=$(/usr/libexec/java_home)
cd $JAVA_HOME
sudo ln -s include Headers
sudo cp include/darwin/* include/
cd -
Note that instead of changing setup.py, I'm changing my JDK install. This has the advantage of fixing the issue for other projects.
For those trying to install on Mountain Lion, I had to further edit the setup.py file to include the header files here:
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers

Categories

Resources