397

I've installed JDK 7u7 downloaded from oracle's website. But after installation, the terminal is still showing java version 6

$java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

any idea why java 7 is not showing up?

Ans: OK, the problem has been resolved. Here is the answer: I found that my Terminal has a .bash_profile and the java home variable is set to 1.6

export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home"

So this is the line causing the problem every time I opened a new terminal window. Simply remove this line will solve the problem. You still need to follow what @aleroot said, but if that doesn't work for you, check the .bash_profile (or .bashrc) setting file to see if you've previously exported any java version.

Yang
  • 9,794
  • 15
  • 44
  • 52
  • 24
    I had this problem but I only updated the JRE and not the JDK. Once I updated the JDK it showed the correct version. – Paul Maserrat May 08 '13 at 15:03
  • Migrate this to Ask Different? – Nakilon Nov 09 '13 at 22:11
  • 15
    Just to draw some extra attention to @Mazzy's comment, that's an easy mistake to make. Downloading JRE v7 will cause version 7 to appear when running the online version checker, or the Java control panel thingy, but when invoking Java from the command line you'll be running the older version from your previously installed JDK. So double-check to make sure you installed the JDK and not just the JRE. – Cam Jackson Mar 06 '14 at 03:51
  • 1
    The best way to solve this is to use the `export JAVA_HOME` approach, as [detailed here](http://stackoverflow.com/a/6588410/26510) in a slightly more flexible way. – Brad Parks Oct 19 '16 at 12:57
  • @CamJackson On Mac Sierra I've /Library/Java/JavaVirtualMachines which has jdk and System Preferences > Java what's different between these 2 ? – vikramvi Jul 25 '17 at 07:56
  • 5
    Let me stress this in capital letters: MANY PEOPLE LANDING ON THIS PAGE WILL JUST NEED TO DOWNLOAD AND INSTALL THE LATEST JDK. THE JAVA CONTROL PANEL ONLY UPDATES THE JRE. – Walter Tross Oct 20 '17 at 09:24
  • Oracle's management of Java versions on MacOS is AMAZINGLY inconsistent and confusing. And it's been terrible for a &)*^#$ decade! – Arthur Jan 20 '21 at 23:29

27 Answers27

299

Oracle's installer puts java inside the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin. And it doesn't overwrite /usr/bin/java. So, if you issue a

whereis java

in the terminal, it'll return /usr/bin/java. (which in turn points to /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java, which is Apple's 1.6 version).

So, if you want to use the new java version, replace the /usr/bin/java symlink so that it points to /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java instead:

sudo rm /usr/bin/java
sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin
Anton Rudeshko
  • 1,039
  • 2
  • 11
  • 20
Ákos
  • 3,221
  • 2
  • 12
  • 9
  • I've done this on a few machines and I always forget how! :) Thanks for this. I'm now running java 7 in osx 10.8.4. – BingeBoy Jul 19 '13 at 04:01
  • 22
    Here is the command: sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin – Binarian Sep 11 '13 at 04:46
  • 1
    You should also make sure you have the JDK and not just the JRE as the Plug-In will show Java 7 if only the JRE is installed, so it may be better to soft-link to the JDK version, e.g., /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java . Note that it's also possible an apple update may revert the symlink. – ldg Sep 21 '13 at 23:34
  • 11
    Viktor's command works. But you may also need to be sure you remove the existing java symlink `rm /usr/bin/java` – Matt Florence Jan 27 '14 at 03:10
  • 7
    Until Oracle folks improve this process, here's a HOWTO of the whole process of installing java on an osx system, up until and including this final symlink step: https://gist.github.com/johan/10590467 – ecmanaut Apr 13 '14 at 16:21
  • 7
    Remember you would also have to update the links for jar, jarsigner, javac, javadoc, javah, javap, javaws, jcmd, jconsole, jdb, jhat, jinfo, jmap, jmc, jps, jrunscript, jsadebugd, jstack, jstat, jstatd, and jvisualvm to provide a coherent environment. That makes this option rather burdensome. – Joe Atzberger Sep 12 '14 at 20:32
  • This works for java 1.8.0 update as well and now suspecting this will be the way to for some time. Why won't Apple just comply? – Laser Hawk Jul 20 '15 at 21:58
  • Should the symlink be /usr/bin/java instead of /usr/bin? – Damon Aug 24 '15 at 16:23
  • 64
    i got `rm: /usr/bin/java: Operation not permitted` – Aditya Oct 23 '15 at 02:41
  • 7
    It should be noted that as of OS X El Capitan (10.11), files like `/usr/bin/java` can only be modified by Apple-signed processes unless you boot into recovery mode. It's probably a better idea to make sure `/usr/local/bin` is on your path and symlink into that directory. – Lucien Greathouse Dec 22 '15 at 19:40
  • 2
    Installing JDK fixed it for me. This way seems like a hack as we're not linking all the other binaries as @JoeAtzberger has mentioned. – iamyojimbo Jan 26 '16 at 07:32
  • @Aditya This is due to the new System Integration Protection (a.k.a rootless) that is now on El Capitan. See this [http://stackoverflow.com/questions/33007889/move-usr-bin-java-in-terminal](http://stackoverflow.com/questions/33007889/move-usr-bin-java-in-terminal) on how to disable it. – BigHeadCreations Apr 15 '16 at 01:02
  • 3
    I would suggest creating the symlink under `/usr/local/bin` because of the rootless policy – tarikakyol Nov 10 '16 at 09:34
  • 37
    Or `export PATH="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:$PATH" ` – Mick Dec 17 '16 at 00:44
  • 3
    @Mick You should make your comment an answer as it is more correct than this answer and resolves the issues better than other answers – JonTroncoso May 02 '17 at 21:01
  • For me following commands worked. sudo rm /usr/bin/java sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java java – paraS elixiR Feb 28 '18 at 10:07
115

Install the JDK 7 and this problem will solve itself.

Be sure to get the Java Development Kit (JDK) which includes compilers and stuff like that, rather than just the Java Runtime Environment (JRE) .

j-beda
  • 123
  • 4
BrainO2
  • 1,372
  • 1
  • 8
  • 6
  • 7
    instal the full JDK, not only the JRE. – BrainO2 May 07 '14 at 15:23
  • 3
    Confirmed OK on OSX 10.9.4. It doesn't change the /usr/bin link, it changes stuff underneath it. So `/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java # But: /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java -version java version "1.7.0_67"` – Joe Atzberger Sep 12 '14 at 20:49
  • 1
    Also worked for JDK 1.8 -- (install JDK 1.8 instead of JRE 1.8) – Mark Chackerian Apr 28 '15 at 19:56
  • I tried to install Java 1.8, but that didn't work on El Capitan. Installing 1.7 solved my problems. – SPRBRN Oct 17 '15 at 11:59
105

vi ~/.bash_profile

add

export JAVA_HOME=`/usr/libexec/java_home -v 1.7`

This tells your /usr/bin/java link target to use the latest Java 7 Package installed in

/Library/Java/JavaVirtualMachines/

So for JDK 1.7.0_17 JAVA_HOME would be:

/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home

Note: There were a lot of change in this area recently to move Mac OS X from Appels own System integrated Java packages to Oracle based Java Packages. The above solution is working fine as of Mac OS X 10.8.2

Uwe Günther
  • 2,971
  • 2
  • 21
  • 26
  • 4
    +1 for this answer which is imo the correct one because it works on versions of Mac OS before and after 'Java Preferences' was removed, and by showing the "-v" option it demonstrates how you can use java 6 even if java 7 is installed (which is what I want). Hence on my Mac running Lion (10.7.5) I use the same command with "-v 1.6". This is crucial because I need Java 6 and Oracle doesnt provide one for Mac OS - only Java 7, and this allows me to use the installed JAva 6 even though Java 7 is installed. – Rhubarb May 20 '13 at 11:43
  • 1
    Also, to make it more flexible: http://mikemainguy.blogspot.com/2014/11/easily-changing-java-versions-in-osx.html – Mainguy Nov 26 '14 at 18:45
  • additional info [can be found here](http://stackoverflow.com/a/6588410/26510) for this awesome answer! – Brad Parks Oct 19 '16 at 12:54
  • This worked for me in Sierra 10.12 after installing the 1.8 JKD the export worked by changing 1.7 to 1.8. Great answer using the java_home utility!! – Scott Byers Mar 22 '17 at 20:04
  • For .cshrc `setenv JAVA_HOME \`/usr/libexec/java_home -v 15\`` – Sam Barnum Nov 28 '20 at 03:23
65

Because you need to enter in Java Preferences pane and flag only the JVM 7 in this way :

Java Preferences

To easily and quickly open the Java Preferences pane in Mac OS X you can simply call spotlight with +SPACE and type System Preferences it will show up in the last row of the window.

Community
  • 1
  • 1
aleroot
  • 71,077
  • 30
  • 176
  • 213
  • Open Spotlight(CTRL+SPACE) type JAva Preferences and you will find it as first result . – aleroot Oct 06 '12 at 07:17
  • 3
    yes, found it. but still version 1.6 in terminal, do i need to reboot or something – Yang Oct 06 '12 at 07:19
  • 1
    This panel does no longer exist in 10.8. Alternatives? – Pepijn Feb 07 '13 at 13:08
  • @Pepijn Install the latest JDK from Oracle, it will set the java 7 as default ... – aleroot Feb 07 '13 at 13:51
  • 70
    @Pepijn The panale is history as of Mac OSX 10.8.2 and there isn't really a need for it anymore. Instead you have to use `export JAVA_HOME=\`/usr/libexec/java_home -v 1.7\`` to switch to the latest Java 7 JDK from Oracle. – Uwe Günther Mar 09 '13 at 02:54
  • @cr0nicz Not on all versions — and further, the spotlight key-command is customizable. – aramis Oct 23 '13 at 06:03
  • 23
    I think they got rid of Java Preferences at some point. It's not found by Spotlight on my box. Running 10.8.5. – quickshiftin Dec 09 '13 at 18:58
  • 1
    You can find the exact location of JAVA_HOME under -> system preferences -> java. Click "Java" tab. Click view. The Path variable shows your JAVA_HOME (tile /Home). – agaase Jul 30 '14 at 11:02
  • There is nothing mentioning Java in System preferences (10.10.5) – trainoasis Oct 27 '15 at 07:36
  • This discussion might help too: https://discussions.apple.com/thread/6527269?start=0 Install the JDK, not the JRE. It worked for me very well. Mac OS X 10.11.6. – M. Beausoleil Aug 03 '17 at 15:14
56

In my case, the issue was that Oracle was installing it to a different location than I was used to.

Download from Oracle: http://java.com/en/download/mac_download.jsp?locale=en

  1. Verify that it's installed properly by looking in System Prefs:

    • Command-Space to open Spotlight, type 'System Preferences', hit enter.
    • Click Java icon in bottom row. After the Java Control Panel opens, click 'Java' tab, 'View...', and verify that your install worked. You can see a 'Path' there also, which you can sub into the commands below in case they are different than mine.
  2. Verify that the version is as you expect (sub in your path as needed):

    /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version

  3. Create link from /usr/bin/java to your new install

    sudo ln -fs /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java

  4. Sanity check your version:

    java -version

dale.hamill
  • 561
  • 4
  • 2
36

I had run into a similar issue with terminal not updating the java version to match the version installed on the mac.

There was no issue with the JAVA_HOME environmental variable being set

I have come up with a temporary and somewhat painful but working solution.

In you .bash_profile add the line:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home"

(This is the path on my machine but may be different on yours, make sure to get yours. The paths should match up to /Library/Java/JavaVirtualMachines/)

the run source ~/.bash_profile

As I mentioned this is a temporary band-aid solution because the java home path is being hard-coded. There is really no way to set the path to get the latest as that is what Apple is supposedly doing for terminal already and the issue is that Apple's java_home environment variable is not getting updated.

random-forest-cat
  • 33,652
  • 11
  • 120
  • 99
Derek
  • 386
  • 3
  • 2
  • 4
    The directory is empty. $ ls /Library/Java/JavaVirtualMachines/ – Pepijn Feb 13 '13 at 21:52
  • 1
    You probably have an issue with where you installed java 7. Please go to [oracle's website](http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u11-oth-JPR). Click on the "Java SE Development Kit 7u11" link, accept the license agreement, and download "jdk-7u11-macosx-x64.dmg". Use the dmg to install Java 7 and this should put it in your JavaVirtualMachines directory. – Derek Feb 16 '13 at 00:19
  • This is one solution on Mojave 10.14.1 in early 2019 – bitsand Feb 07 '19 at 02:01
26

Since El Capitan, it is difficult to delete the /usr/bin/java symlink, because of the introduction of the new "rootless" policy.

Therefore, I simply added the path to the latest java version (in my case this is /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin) to the PATH in my .bashrc file:

# Use latest java version
export PATH=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:$PATH

To reload your .bashrc file for the current session, run source ~/.bashrc in the shell. You only have to do this for sessions that had been started before changing the .bashrc file.

Now the latest version is used, when you use java in the shell.

TabeaKischka
  • 793
  • 6
  • 15
  • 1
    This particular solution worked for me on my mac os x el capitan. I did not bypass the the security set up on el capitan, but installed java version 1.8. Doing export JAVA_HOME=/my specific path etc etc/ did not work (after going to preferences and locating the path to 1.8). Please note 1.6 is still installed. I had to create a .bashrc file and set the path as described here. I ran java -version and shazzam! it worked. – umbregachoong Jul 20 '16 at 19:49
  • I so wanted this to work as I'm on El Capitan and can't get any other solution to function. I created a '.bashrc' file and added the line as above, but if I type 'java -version' I still get 1.6. Anything I might have overlooked? – noLongerRandom Sep 06 '16 at 20:17
  • @user3810073 maybe you need to run `source .bashrc`, in order to reload the contents of .bashrc – TabeaKischka Oct 11 '16 at 12:39
  • Worked for me. I added the line to .bash_profile (in the home directory of my user), then source .bash_profile. Then java -version gave me the latest one. Thanks! – mrmuggles Nov 01 '16 at 19:02
  • This can also be achieved by symlinking to `/usr/local/bin` like this: `sudo ln -sf "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java" /usr/local/bin/java` That assuming `/usr/local/bin` is before `/usr/bin` in your `$PATH` which should be by default. – lifeofguenter Apr 02 '17 at 20:55
21

Update

brew tap adoptopenjdk/openjdk
brew cask install adoptopenjdk/openjdk/adoptopenjdk8

https://stackoverflow.com/a/28635465

Old version For me the easiest and cleanest way to go is to install Java using homebrew like described here:

https://stackoverflow.com/a/28635465

brew update
brew cask install java
Bernhardt Scherer
  • 1,818
  • 3
  • 14
  • 21
14

You can execute following command in your terminal :

export PATH="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:$PATH"

And this replaces the java old with new one.

Amulya Kashyap
  • 2,333
  • 17
  • 25
13

The basic issue: /usr/bin/java is pointing to one provided by OSX itself initially (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java) We need to point this to the one downloaded by the JDK installer. The below steps are for OSX 10.10.4 Yosemite.

  • Open System Preferences -> select Java. The Java window opens.
  • Click on Java tab at the top. Click on 'View' button.
  • The Java Runtime Environment Settings tab opens as below: JRE Settings tab
  • Double click on the Path item and copy the path (cmd+c). This is the latest one installed by the JDK installer/updater. In my case, the path was /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
  • Open terminal. In this step, we are going to point (symbolic link, ln -s command) the system java binary to the latest one, which we discovered in the previous step. Run the below command:

sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java

Thats it. To verify, you can just run java -version on the terminal. It should output the latest version that you installed/updated to.

Aswin Kumar
  • 5,158
  • 5
  • 34
  • 39
  • 2
    Works for me, except that I had to add -f to ln command. Otherwise if failed with ln: /usr/bin/java: File exists – Dale Mar 23 '16 at 23:40
  • in my case I'd to use `usr/local/bin` instead of `usr/bin` in terminal command – iAkshay May 24 '17 at 13:04
  • I am getting "operation not permitted". – Shardul Nov 16 '17 at 00:48
  • Obtaining the path in this manner is ideal. I then was able to export it and reload bashrc to resolve the version issue. In my case I was migrating from version 7 to 8 on Mojave 10.14.1 – bitsand Feb 07 '19 at 02:04
10

I did

export JAVA_HOME=`/usr/libexec/java_home`

and that fixed my Java 8 issue.

before:

java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

after:

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)
Climbs_lika_Spyder
  • 6,004
  • 3
  • 39
  • 53
7

http://www.java.com/en/download/faq/java_mac.xml is a nice place to understand, while Apple is stopping support to Java, why Java Preferences doesn't exist anymore and rely on System_Preferences => Java => Java if Java 7 from Oracle is installed.

revher
  • 191
  • 3
  • 2
    This is good information, but you should really provide more details than just a link. If the link is broken in the future, your answer really won't be very useful. – psubsee2003 Oct 26 '12 at 16:19
7

May I suggest you to have a look at the tool Jenv

This will allow you to switch at any time between your installed JVMs.

Simply as:

jenv global oracle-1.7

then later for test purpose:

jenv global oracle-1.6

And you have much more commands available.

TitiMoby
  • 83
  • 1
  • 7
  • +1 for this answer as you can utilize Homebrew, if you're using it already in your OS X system. Much cleaner than others I say. More info here: http://www.jenv.be/ – piku Sep 17 '14 at 16:37
6

Hard-coding the JAVA_HOME path might not be the best idea. The /usr/libexec/java_home utility sill works for me on Mac OSX Lion 10.7.5 and JDK 1.7.0_13. According to its man page, it is meant to be used with Apple's old Java Preferences pane, but it appears to be working with the replacement provided by Oracle (Java Control Panel). For example running /usr/libexec/java_home -V lists all installed JDKs (both 1.6.* and 1.7.*) on my machine.

So, as discussed in other threads (e.g. What should I set JAVA_HOME to on OSX), I would still recommend adding the following line to your .bash_profile:

export JAVA_HOME=$(/usr/libexec/java_home)
Community
  • 1
  • 1
zagyi
  • 17,223
  • 4
  • 51
  • 48
  • I would agree with your comment here, because that is best practice, but for some reason the java_home environment variable is not being set correctly which is why this does not work. I believe in Apple's latest update your suggestion is the default action for JAVA_HOME in terminal and other related applications by default. – Derek Feb 16 '13 at 00:28
  • @Derek What do you exactly mean on "the java_home environment variable is not being set correctly"? According to [this article](https://developer.apple.com/library/mac/#releasenotes/Java/Java_OSX2012006Java_MacOSX10.6Update11RN/NewandNoteworthy/NewandNoteworthy.html) the `/usr/libexec/java_home` utility is meant to be working also with java 7 versions, and it returns the path to the most up-to-date JDK installed. It does perfectly work on my machine. – zagyi Feb 16 '13 at 14:05
  • 1
    yes it is supposed to work however it does not for people with the problem that pepijin had mentioned. – Derek Feb 20 '13 at 01:22
6

This is nuts! How does Oracle provide an installer that doesn't install anything!?

Anyways for me it was:

sudo rm /usr/bin/java
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre/bin/java /usr/bin/java

where 1.8.0_31 is your installed java version...

Pupil
  • 23,834
  • 6
  • 44
  • 66
Kevin Parker
  • 16,975
  • 20
  • 76
  • 105
6

In case if you have several Java versions on your machine and you want to choose it dynamically at runtime, i.e, in my case, I have two versions:

ls -la /Library/Java/JavaVirtualMachines
drwxr-xr-x  3 root  wheel    96B Nov 16  2014 jdk1.7.0_71.jdk/
drwxr-xr-x  3 root  wheel    96B Mar  1  2015 jdk1.8.0_31.jdk/

You can change them by modifying the /etc/profile content. Just add (or modify) the following two lines at the end of the file:

export JAVA_HOME=YOUR_JAVA_PATH/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

In my case, it should be like the following if I want to use:

Java 7:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

Java 8:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

After saving the file, please run source /etc/profile and it should work. Here are results when I use the first and second option accordingly:

Java 7:

java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)

Java 8:

java -version 
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)

The process is similar if your java folder is located in different locations.

Hoa Nguyen
  • 13,452
  • 11
  • 45
  • 44
5

Simple Solution

export PATH="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:$PATH"
Community
  • 1
  • 1
Mick
  • 30,759
  • 16
  • 111
  • 130
3

I think you can try to install jdk not jre. By installing jdk, the java in /usr/bin/java will be replaced, and all library will work fine.

DDDrop
  • 121
  • 3
3

If you have Homebrew installed, you can install java-switcher to change Java default version more quickly

brew tap andycillin/tap
brew install java-switcher

Then you can use just one command to switch your default Java version.

java-switcher 1.7

or

java-switcher 10
Andy Tran
  • 31
  • 1
1

It is happening because your .bash_profile is not reflecting changes.To reflect it, just use the following command

$ source .bash_profile
Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73
Raghav Sharma
  • 780
  • 10
  • 18
1

You can run this command to find the version of Java that's under /Library/Internet Plugins/:

defaults read /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist CFBundleVersion
Hefewe1zen
  • 111
  • 3
0

Since i have not faced this issue , I am taking a hunch --

Can you please try this :

Where does the soft link "java_home" point to :

ls -lrt /usr/libexec/java_home

Output : (Stunted) lrwxr-xr-x java_home -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home

**ls -lrt /System/Library/Frameworks/JavaVM.framework/Versions My MAC Produces the following :

 lrwxr-xr-x CurrentJDK ->
 /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents**

 lrwxr-xr-x   Current -> A
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.6.0 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.6 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.5.0 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.5 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.4.2 -> CurrentJDK
 lrwxr-xr-x  1 root  wheel   10 Oct 18 14:39 1.4 -> CurrentJDK

Based on this , we might get a hint to proceed further ?

user1428716
  • 2,078
  • 2
  • 18
  • 37
  • read some commentaries on the Internet about Java 7 issues with MAC-OSX and it shows blocked.Refer this : http://www.grep.dk/tag/xprotect-meta-plist/. In XProtect.meta.plist I have Java 7 and Flash listed.Until is playing the Vulnerability Police – user1428716 Feb 14 '13 at 01:00
0

i resolved this issue by re installing Yosemite and then cross check java version on terminal (java -version) and (javac -version) .It work perfectly now.It is not changing to java 7 as version 6 still present on (command + n) libray>java>javavirtualmachine>your javac current version.you need to address to java home .

AJAY
  • 1
0

I resolved this issue with sudo rm /usr/bin/java

And I downloaded and installed the last Java SE Runtime Environment: http://www.oracle.com/technetwork/java/javase/downloads/index.html

sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre/bin/java /usr/bin/java did not work for me because I got Operation not permitted. El Capitan now protects certain system directories in "rootless" mode (a.k.a. System Integrity Protection). It is applicable to macOS Sierra, and probably new macOS versions for the foreseeable future.

Jade Hamel
  • 1,360
  • 1
  • 15
  • 30
0

Installing through distributed JDK DMG from the Oracle site auto-updates everything for me. I have seen (in El Capitan) updating through System Preferences > Java do updates but that do not reflect to command line. Installing through DMG does the job.

Santanu Karar
  • 1,034
  • 1
  • 12
  • 27
0

Check JDK versions installed:

$ ls  /Library/Java/JavaVirtualMachines/
jdk-11.0.2.jdk  jdk1.8.0_91.jdk

Now in your ~/.bashrc export JAVA_HOME specifying the version:

if [ -e /usr/libexec/java_home ]; then
  export JAVA_HOME=$(/usr/libexec/java_home -v 11)
fi

Source the bashrc file and the Java version will be updated:

$ java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
Miguel Mota
  • 20,135
  • 5
  • 45
  • 64
0

The latest 100% effective method:


in bash:

vim ~/.bash_profile

add

export PATH="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin:$PATH"
  • :wq to save
  • cmd+q force quit bash
  • open bash again, and type in java -version

But actually this path points to jre not jdk.

If you want to point the path to JDK, you need

  1. Make sure you have installed JDK not a single JRE runtime
  2. replace previous path to PATH="/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk", you can go to /Library/Java/JavaVirtualMachines to make sure you have installed the version of JDK you expected.
liangli
  • 1,151
  • 9
  • 11