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.
Because you need to enter in Java Preferences pane and flag only the JVM 7 in this way : 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.
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).
The Java Runtime depends on the availability of an Application programming interface (API). Some of the API were added in Mac OS X 10.7.3. Apple has no plans to make those API available on older versions of the Mac OS.
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. Show activity on this post. In my case, the issue was that Oracle was installing it to a different location than I was used to.
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
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) .
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
Because you need to enter in Java Preferences pane and flag only the JVM 7 in this way :
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.
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
Verify that it's installed properly by looking in System Prefs:
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
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
Sanity check your version:
java -version
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.
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.
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
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.
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.
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
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.
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)
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.
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.
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)
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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With