Switching version of Java on Mac

To check the currently installed version of java on your Mac:

$ java -version
java version "1.6.0_65"


(Welcome back to 2006!)


You can download Java 1.7, 1.8 and 1.9 at Oracle and write down WHERE they install it:

http://www.oracle.com/technetwork/java/javase/downloads/index.html




Using SYMBOLIC LINKS I created locations of my various Java locations:

sudo ln -s location_of_JDK "version_name"



for example:

$ sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/ 1.8.0_51




Uki@ Versions $ ls -al
total 72
drwxr-xr-x 12 root wheel 408 Jul 29 12:03 .
drwxr-xr-x 11 root wheel 374 Jul 29 11:50 ..
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 59 Jul 29 12:03 1.8.0_51 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/
drwxr-xr-x 7 root wheel 238 Jul 29 11:50 A
lrwxr-xr-x 1 root wheel 1 Jul 29 11:50 Current -> A
lrwxr-xr-x 1 root wheel 52 Jul 29 11:50 CurrentJDK ->/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
Uki@ Versions $


now I can switch my Java to 1.8 by redirecting CurrentJDK:

Uki@ Versions $ sudo rm -r CurrentJDK
Uki@ Versions $ sudo ln -s 1.8.0_51 CurrentJDK

Check that change took place: 


Uki@ Versions $ ls -altotal 72
drwxr-xr-x 12 root wheel 408 Jul 29 12:07 .
drwxr-xr-x 11 root wheel 374 Jul 29 11:50 ..
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 Jul 29 11:50 1.6.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 59 Jul 29 12:03 1.8.0_51 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/
drwxr-xr-x 7 root wheel 238 Jul 29 11:50 A
lrwxr-xr-x 1 root wheel 1 Jul 29 11:50 Current -> A
lrwxr-xr-x 1 root wheel 8 Jul 29 12:07 CurrentJDK -> 1.8.0_51
Uki@ Versions $ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)










~~~~~~~~~~~~~~~~~~~~~~~










It is also useful to create JAVA_HOME as a lot of apps use that.




Open your shell startup script, most of the time it is ~/.profile







edit ~/.profile






--------------------------------

# JAVA updated: May 14, 2015
# other versions: /System/Library/Frameworks/JavaVM.framework/Versions/
# set up what CURRENT points to
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
# add Java home to path
export PATH=${PATH}:${JAVA_HOME}/bin






--------------------------------






$ java -version


java version "1.8.0_20-ea"


Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)



Java HotSpot(TM) 64-Bit Server VM (build 25.20-b05, mixed mode)










If you mess up you will get messages like:


$ java -version



Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/bin/java" (-1)






That is because the folder you point at has to have /bin/java in it.


Please note that your system Java level is independent from you Android Eclipse Java setting (1.6)









http://stackoverflow.com/a/23396850/3566154










If you like this post, please give me your 2 cents ($0.02 litterally) to show token of appreciation and encourage me to write more:

Donate Bitcoins



As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles