2

I just installed Oracle's Java version 7u7 on my Mac (running OSX Mountain Lion). However, when I run java -version it still displays the old version (6u29).

Displaying Java 6 and 7 side by side

How do I fix this? Do I even need to fix this? What version will browsers (Firefox) use in this case? And what version will be used when I run Java applications directly?

I've seen this question but this doesn't work in my situation (probably because this question is about the JRE and the other question about the JDK). In my case the Java Preferences app only displays Java 6 versions (32 bit and 64 bit).

enter image description here

Update:

  • which java points to /usr/bin/java
  • /usr/bin/java is a symlink to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
  • /System/Library/Frameworks/JavaVM.framework/Versions/ only contains the folder A (awesome version name) - which Current points to.
4
  • Did you reboot after installing 7up7? I don't know exactly how it works on Mac, but if it's anything like linux, it'll go through your path (environment variable) looking for the java executable. Sometimes java will explicitly put the directory into the path on installation, other times it'll just assume the place it's installing to is on the path.
    – MBraedley
    Sep 25, 2012 at 15:08
  • Reboot didn't solve the problem. Sep 25, 2012 at 18:11
  • run which java from terminal. It'll tell you where the system is running the executable. For instance, on the linux machine in front of me, it says it's /usr/bin/java, and the ll /usr/bin/java says that it's a sym link to the actual install.
    – MBraedley
    Sep 25, 2012 at 18:52
  • I've updated the question with the information. However, they don't seem to help much. Sep 26, 2012 at 7:33

4 Answers 4

2

Ok, thanks to MBraedley I found the solution.

Quoting from the JRE 7 Installation Guide for Mac OS X:

Installing a JRE from Oracle will not:

  • Update java -version symlinks or add java to your path.
  • Show the installed JRE in the Java Preferences.app

To be able to do the above, you need to install the JDK.

1
  • 1
    Any idea how to do this when the JDK is installed? /usr/libexec/java_home gives me /Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home, but the symlinks still point to /System/Library/Frameworks/JavaVM.framework/Versions/Current/.
    – Koraktor
    Feb 14, 2013 at 21:22
1

put this in your start up script (.profile, .bash_profile etc):

export JAVA_HOME=$(/usr/libexec/java_home)

It's possible you are setting JAVA_HOME to the wrong version. Before Java 7, I had

export JAVA_HOME=/Library/Java/Home/

and I was still getting Java 6.

1

Yes Sometimes this happen as your machine not reflect the correct version. First find out where do you store the environment variables- 1. emacs 2. bash_profile 3. zshrc file

Steps to Set up the environment variable :-

  1. Download the jdk from JAVA
  2. install it by double click
  3. Now set-up environment variables in your file

    a. For emacs.profile you can use this link OR see the screenshot below enter image description here

    b. For ZSH profile setup -

    1. export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
    
    2. source ~/.zshrc - Restart zshrc OR open another terminal 
    
    3. echo $JAVA_HOME - make sure path is set up properly 
       ----> /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
    
    4. java -version 
    
       -->  java version "1.8.0_112"  Java(TM) SE Runtime Environment (build 1.8.0_112-b16)Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)
    

All set Now you can easily upgrade or degrade the JAVA version..

0

You can have multiple versions of Java JDK installed at the same time. You can, then, set the version of the JDK to use within terminal. You can also set the version you want as the default in, ~/.bash_profile

export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`
export JAVA_HOME=`/usr/libexec/java_home -v '1.7*'`
export JAVA_HOME=`/usr/libexec/java_home -v '1.8*'`

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .