Change java version (Mac)

16,397

Solution 1

I believe OS X (at least 10.8) uses the following paths:

  • JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current
  • JDK: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK

Those are symlinks, which you can update to point to your 1.7 installation.

You can verify this fairly easily:

a) run which java to check which java executable is being executed. In theory, that should be /usr/bin/java.

b) run ls -la on your java executable, which should tell you where it points (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java on my machine).

I think this should sort your .jar execution issue. If your Java application is wrapped in a .app, I believe it's a bit more complex: if memory serves, the version of java used will depend on the JavaApplicationStub being used by the .app.

Solution 2

$ edit ~/.profile

#Java 1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}


$ java -version

java version "1.8.0_20-ea"

here are the steps:

http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html

Solution 3

You can always add into your profile both on Mac or Linux. Just create if doesn't exist ~/.profile file and there this line:

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

This should work .zshrc as well as .bash_profile are loaded only when terminal window is openned and profile when your graphical environment starts up.

Share:
16,397
Grains
Author by

Grains

Updated on June 25, 2022

Comments

  • Grains
    Grains almost 2 years

    I have 2 java versions on my computer:

    /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
    /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    

    The 1.6.0 is set to default. How can I make my java programs to run 1.7?

    Tried to add:

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

    to my .zshrc file. But this seems to only change the path for my terminals java command.

    Also tried to change the HOME symlink like this:

    cd /Library/Java
    mv Home Home-1.6
    ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/ Home
    

    This had no effect at all.

    Also tried java changer software: http://www.guigarage.com/2013/02/change-java-version-on-mac-os/ But no effect.

    Any idea how to start java programs like .app and .jar files with the 1.7 version by just clicking on them?

    • LMG
      LMG over 10 years
      what does the terminal say if you type java -version?
    • Adam
      Adam over 10 years
      closed as off topic? "...unless they directly involve tools used primarily for programming." The jdk is almost exclusively used for programming.
  • Grains
    Grains over 10 years
    I think that last part is the actual answer to the problem: "version of java used will depend on the JavaApplicationStub being used by the .app.". Guess it´s me doing wrong when using Jar Bundle(no 1.7 support....)
  • Nicolas Rinaudo
    Nicolas Rinaudo over 10 years
    In that case, this might be of interest.
  • Mack
    Mack almost 10 years
    Try to add some of the detailed steps from the link...future users may not have access to it.