1

I have unsuccessfully tried to update my Java to the latest version (1.8.0_151) in order to use some packages in R.

My current version of OSX is macOS Sierra version 10.12.6.

I tried this solution (being able to select the version of Java that I want via the Terminal) but have not been able to get it to work mostly because the latest version is not showing up in my call in the Terminal for:

/usr/libexec/java_home -V

In my Terminal I still see:

Matching Java Virtual Machines (2):
    1.6.0_65-b14-468, x86_64:   "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386: "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 

Where I am expecting to see something like the below (copy and paste from the first solution), even though I have downloaded the latest version of Java and confirmed that it's that latest via my System Preferences.

Matching Java Virtual Machines (3):
1.8.0_05, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
1.6.0_65-b14-462, x86_64:   "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
1.6.0_65-b14-462, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home

Additionally, I have tried this solution, which attempts to re-set the JAVA_HOME within the bash but I do not have permission.

Apologies if I am missing something basic, I have not worked in the Terminal and do not know what it means that I do not have permission / how to update my profile for the latest version of Java.

Additionally, I have tried the following in my Terminal

R CMD javareconf

Which produces the following error, as opposed to mapping to the appropriate version of Java:

Java interpreter : /usr/bin/java
Java version     : 1.6.0_65
Java home path   : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java compiler    : /usr/bin/javac
Java headers gen.: /usr/bin/javah
Java archive tool: /usr/bin/jar
System Java on macOS

trying to compile and link a JNI program 
detected JNI cpp flags    : -I/System/Library/Frameworks/JavaVM.framework/Headers
detected JNI linker flags : -framework JavaVM
clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/System/Library/Frameworks/JavaVM.framework/Headers -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include    -fPIC  -Wall -mtune=core2 -g -O2  -c conftest.c -o conftest.o
conftest.c:4:5: warning: 'JNI_CreateJavaVM' is deprecated
      [-Wdeprecated-declarations]
    JNI_CreateJavaVM(0, 0, 0);
    ^
/System/Library/Frameworks/JavaVM.framework/Headers/jni.h:1936:39: note: 
      'JNI_CreateJavaVM' has been explicitly marked deprecated here
_JNI_IMPORT_OR_EXPORT_ __attribute__((deprecated)) jint JNICALL
                                      ^
1 warning generated.
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o conftest.so conftest.o -framework JavaVM -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation


JAVA_HOME        : /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Java library path: 
JNI cpp flags    : -I/System/Library/Frameworks/JavaVM.framework/Headers
JNI linker flags : -framework JavaVM
Updating Java configuration in /Library/Frameworks/R.framework/Resources
Done.

How can I ensure that the recently downloaded version of Java is being utilized and add it to my profile?

Any and all help would be greatly appreciated!

--UPDATE--

I have been able to map the appropriate JDK version to my .bash_profile by following these youtube steps.

The issue still remains in RStudio where it is not pulling the right Java version when I try to install the RWeka package.

How can I link the appropriate version in my RStudio?

The error for RWeka installation is below:

** package ‘RWeka’ successfully unpacked and MD5 sums checked
Need at least Java version 1.7/7.0.
ERROR: configuration failed for package ‘RWeka’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/RWeka’
Warning in install.packages :
  installation of package ‘RWeka’ had non-zero exit status
santorch
  • 151
  • 1
  • 14
  • You need to describe the versions of Java you installed, how, the version of OS X, etc. Describe your problem and what you tried to do to solve it step by step, pointing out what you expected to happen, what actually happened, how they differ, etc. – pvg Nov 11 '17 at 22:11
  • Thanks for the advice - do my edits help clarify things @pvg? – santorch Nov 11 '17 at 22:18
  • Could you go to _System Preferences_ > _Java_, drag and change the preferred order of different Java versions? – Mincong Huang Nov 11 '17 at 22:21
  • Are you sure you successfully downloaded and installed jdk 8? from oracle? It should be showing up in that list produced `java_home` if it installed. – pvg Nov 11 '17 at 22:23
  • @MincongHuang When I go into System Preferences > Java, there is only 1 option, which is 1.8.0_151 – santorch Nov 11 '17 at 22:27
  • In this case, I think you've configured your Java version properly to Java 8. You can confirm that by typing `java -version` in your terminal. – Mincong Huang Nov 11 '17 at 22:29
  • @pvg I tried re-installing and it says that my version is the latest – santorch Nov 11 '17 at 22:31
  • @MincongHuang When i run that, it still shows as the version I referenced in my initial questions... this has been leading me to be quite confused....but also assuming there is something basic that I am missing here – santorch Nov 11 '17 at 22:32
  • Have you done `R CMD javareconf` yet? – alistaire Nov 12 '17 at 00:16
  • @alistaire I tried your code and produced the error that I received in my original post. How do I interpret this error? – santorch Nov 12 '17 at 16:01
  • That’s not an error. I’d have to dig, but I believe `R CMD javareconf` uses the version the `$JAVA_HOME` environment variable points to, which for you is 6. Set it in `~/.bash_profile` (or equivalent) with `export JAVA_HOME="path/to/your/desired/java/version"`. – alistaire Nov 12 '17 at 16:48
  • @alistaire when i run `~/.bash_profile` in the Terminal, I get 'Permission denied' also, when I run the `export JAVA_HOME="path/to/your/desired/java/version"` and then check `java -version` it does not update for me and still shows version 1.6. – santorch Nov 12 '17 at 22:30
  • `.bash_profile` is a text file in your user directory that is run at the start of each bash session. Edit it with a text editor, e.g. `nano ~/.bash_profile`. You'll also need to set `$PATH`, which is the list of filepaths the shell will search (in order) for programs (in this case `java`, `javac`, etc.). For anything called from bash, you can set it in `.bash_profile` just like `$JAVA_HOME`. If you need it set such that it can be accessed from R run in RStudio and such, you'll need to set it via `paths.d`. Search a bit, and you'll find a lot of questions and tutorials on the subject. – alistaire Nov 12 '17 at 22:41
  • @alistaire through some digging I found that I had downloaded Java, not the JDK, so I downloaded version 1.8 and followed some steps to save the v 1.8 JDK to my `.bash_profile` - thank you. Can you explain the last part a bit on setting `paths.d` for R or help to point me in the right direction? – santorch Nov 12 '17 at 23:50
  • If the package works with the `$PATH` set in `.bash_profile` when used via R in the Terminal, but not RStudio, you can put a file in `/etc/paths.d/` containing just the path you want to append to `$PATH`, which will apply for GUI apps too. [Here are some other ways](https://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x), though some are now outdated. – alistaire Nov 13 '17 at 01:10
  • "Java" can refer to either the JRE or the JDK (which includes the JRE). If Java-based packages are precompiled, the JRE may be enough, but if you're building from source, you'll need the compilers in the JDK. [Homebrew](https://brew.sh/) can make installing and updating a lot easier (`brew cask install java8`), and puts things in sensible places so you don't need to edit your `$PATH` for everything you install. – alistaire Nov 13 '17 at 01:10

0 Answers0